0

我有一个带有几列的 Windows 窗体中的 Janus Gridex。我想将此 GridEx 中所有列的 FilterEditType 更改为 Checklistbox。因此用户可以根据一个或多个值过滤每一列。

请给我 C# 或 VB.net 中的示例代码。

4

1 回答 1

0

您需要为此添加某些事件,首先制作 GridEx 列FilterEditType = Custom 然后为每个列 FilterEditType 添加 Janus.Windows.GridEX.EditControls.CheckedComboBox。例如:添加此事件

    private void grdTest_InitCustomEdit(object sender, Janus.Windows.GridEX.InitCustomEditEventArgs e)
    {
        if (e.Column.Key == "ColumnName")
        {
            cboTest.Visible = true;
            e.EditControl = cboTest;
        }
    }
    private void grdTest_EndCustomEdit(object sender, Janus.Windows.GridEX.EndCustomEditEventArgs e)
    {

       //this (dtTest) datatable is actually the datasource assigned for the grid
        dtTest.DefaultView.RowFilter = string.Empty;
        cboTest.Visible = false;
        string Filter = string.Empty;
        if (cboTest.CheckedItems != null)
        {
            foreach (GridEXRow row in cboTest.DropDownList.GetCheckedRows())
            {
                if (Filter != string.Empty)
                    Filter += " OR ColumnName = '";
                else Filter = "( ColumnName = '";
                Filter += row.Cells[2].Value;
                Filter += "'";
            }
            Filter += " )";
        }


        dtTest.DefaultView.RowFilter = Filter;
        grdTest.DataSource = dtTest.DefaultView;
    }
    private void grdTest_ClearFilterButtonClick(object sender, Janus.Windows.GridEX.ColumnActionEventArgs e)
    {
        if (e.Column.Key == "ColumnName")
            cboTest.CheckAll();

        grdTest_EndCustomEdit(null, null);
    }

然后对于选中的组合,您需要根据需要设计多列,但一列应该是 CheckBox 并使其 ActAsSelector = True,上面的示例选中的组合实际上有 3 列,第一个复选框,第二个是 ID (主键),最后一个是名称。我使用名称列来过滤数据表。在组合的 DropDown 事件中,从 GirdEx 数据源为其分配数据源:

    private void cboTest_DropDown(object sender, EventArgs e)
    {
        int C = 1;
        DataRow DR;
        DataTable dtComboDS= new DataTable();
        dtComboDS.Columns.Add("ID", typeof(int));
        dtComboDS.Columns.Add("Name", typeof(string));
        var depts = (from x in dtTest.AsEnumerable() select x.Field<string>("ColumnName")).ToList();// dtTest is actually the datasource assigned for the GridEx
        foreach (var Row in depts.Distinct().ToList())
        {
            DR = dtComboDS.NewRow();
            DR["ID"] = C++;
            DR["Name"] = Row;
            dtComboDS.Rows.Add(DR);
        }
        cboTest.DropDownDataSource = dtComboDS;
    }
    private void cboTest_CloseUp(object sender, EventArgs e)
    {
        cboTest.Visible = false;
        grdTest.UpdateData();
    }

在特写事件中隐藏选中的组合并更新网格以获得结果。希望这会有所帮助!祝你好运。

于 2019-12-15T04:30:36.793 回答