i具有Windows窗体中的Janus Gridex,其中包含几列。我想将此GridEx中所有列的FilterEditType更改为Checkboxbox。因此,用户可以基于一个或多个值过滤每一列。
请在C#或VB.net中给我示例代码。
您需要为此添加一些事件,首先创建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();
}
在特写事件中,隐藏选中的组合并更新网格以获取结果。希望这会有所帮助!祝你好运。