如果是要绑定一个datatable 的话,可以使用MultiColumnComboBoxCellType
以及你需要的模糊查询功能,也可以在此基础上扩展
自定义单元格类型继承此类型,下面有一个参考代码,注意:因为此类型还是会自动填充单元格中的数据,因此无法完全实现模糊搜索,仅能首字母搜索
使用自定义类型
- fpSpread1.ActiveSheet.Cells[6, 6].CellType = new FilterComboCellType(datatable dt) ;
复制代码
自定义类型
- public class FilterComboCellType: FarPoint.Win.Spread.CellType.MultiColumnComboBoxCellType
- {
- DataTable dt;
- public FilterComboCellType(DataTable dt)
- {
-
- this.EditorValueChanged += FilterComboCellType_EditorValueChanged;
- this.DataSourceList = dt;
- this.AutoSearch = FarPoint.Win.AutoSearch.SingleCharacter;
- this.DataColumn = 1;
- this.ColumnEdit = 1;
- this.ButtonAlign = FarPoint.Win.ButtonAlign.Right;
- this.ListAlignment = FarPoint.Win.ListAlignment.Right;
- this.ListWidth = 500;
- this.ListOffset = 5;
- this.MaxDrop = 5;
- this.dt = dt;
- }
- private void FilterComboCellType_EditorValueChanged(object sender, EventArgs e)
- {
- if (this.GetEditorValue() == null || string.IsNullOrEmpty(this.GetEditorValue().ToString()))
- {
- this.DataSourceList = dt;
- return;
- }
- string condition = dt.Columns[1].ColumnName + " like '%"+this.GetEditorValue()+"%'";
- DataTable newdt = new DataTable();
- newdt = dt.Clone();
- DataRow[] dr = dt.Select(condition);
- for (int i = 0; i < dr.Length; i++)
- {
- newdt.ImportRow((DataRow)dr[i]);
- }
- this.DataSourceList = newdt;
- }
- }
复制代码 |