版主:您好,麻烦帮看下 wpf下Flexgrid的c1comboBox列模糊查询的问题:
1、Xaml设置flexgrid的列:
<c1:C1FlexGrid.Columns>
<c1:Column Header="姓名" HeaderHorizontalAlignment="Center">
<c1:Column.CellEditingTemplate>
<ItemContainerTemplate>
<c1:C1ComboBox IsEditable="True" KeyUp="UIElement_OnKeyUp" >
</c1:C1ComboBox>
</ItemContainerTemplate>
</c1:Column.CellEditingTemplate>
</c1:Column>
<c1:Column Header="代码" HeaderHorizontalAlignment="Center"></c1:Column>
</c1:C1FlexGrid.Columns>
<c1:C1FlexGrid.Rows>
<c1:Row></c1:Row>
<c1:Row></c1:Row>
</c1:C1FlexGrid.Rows>
2、窗体构造函数 Flexgrid绑定datatable:
//C1FlexGrid数据源
DataTable dt = new DataTable();
dt.Columns.Add("Name", Type.GetType("System.String"));
dt.Columns.Add("ComList", Type.GetType("System.Int16"));
DataRow dr = dt.NewRow();
dt.Rows.Add(dr);
dr = dt.NewRow();
dt.Rows.Add(dr);
FlexGrid.ItemsSource = dt.DefaultView;
3、窗体 的loaded事件:
employee = new Dictionary<int, string>();
employee.Add(1, "张三");
employee.Add(2, "张四");
employee.Add(3, "赵五");
employee.Add(4, "赵六");
4、OnKeyUp事件:
private void UIElement_OnKeyUp(object sender, KeyEventArgs e)
{
FlexGrid.StartEditing(true);
var cb = sender as C1ComboBox;
if (cb == null) return;
if (cb.IsDropDownOpen) return;
var name = cb.Text;
var value = from pair in employee where pair.Value.Contains(name) select pair;
if (value.Any())
{
cb.Items.Clear();
foreach (var item in value)
{
cb.Items.Add(item.Value);
}
}
//cb.EditCompleted= true;
//cb.Focus();
FlexGrid.StartEditing(false);
}
5、单元格中输入字符:
但焦点离开单元格内容和查询结果消失,
6、查询结果出现在当前列的所有行,能否只限定在当前行?
谢谢!
|