解决表格记录复选组件ColumnHeaderCheckBox排序出现勾选混乱问题
解决表格记录复选组件ColumnHeaderCheckBox排序出现勾选混乱问题
扫一扫加微信
用户反馈的问题:
原因: 点击表格列头进行排序或过滤记录会出现已勾选的记录顺序混乱。
解决方案:
在表格组件(GridView)的排序事件(EndSorting)内还原清空已勾选的记录,代码如下:
C# Code:
private void gridView1_EndSorting(object sender, EventArgs e)
{
_checkColumn.ClearSelection();
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
{
_checkColumn.ClearSelection();
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
ColumnHeaderCheckBox 组件的ClearSelection方法:
C# Code:
public void ClearSelection()
{
_Selection.Clear();
_CheckedRows.Clear();
Invalidate();
}
private void Invalidate()
{
View.BeginUpdate();
View.EndUpdate();
//View.Invalidate();
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
{
_Selection.Clear();
_CheckedRows.Clear();
Invalidate();
}
private void Invalidate()
{
View.BeginUpdate();
View.EndUpdate();
//View.Invalidate();
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
演示源码:
C# Code:
public partial class Form1 : Form
{
ColumnHeaderCheckBox _checkColumn;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Rows.Add(100, "test111");
dt.Rows.Add(200, "test222");
dt.Rows.Add(201, "test220002");
dt.Rows.Add(300, "test333");
dt.AcceptChanges();
gridControl1.DataSource = dt;
_checkColumn = new ColumnHeaderCheckBox(gridView1, gridColumn3);
}
private void gridView1_EndSorting(object sender, EventArgs e)
{
_checkColumn.ClearSelection();
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
{
ColumnHeaderCheckBox _checkColumn;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Rows.Add(100, "test111");
dt.Rows.Add(200, "test222");
dt.Rows.Add(201, "test220002");
dt.Rows.Add(300, "test333");
dt.AcceptChanges();
gridControl1.DataSource = dt;
_checkColumn = new ColumnHeaderCheckBox(gridView1, gridColumn3);
}
private void gridView1_EndSorting(object sender, EventArgs e)
{
_checkColumn.ClearSelection();
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
参考文章:
C#列复合勾选组件ColumnHeaderCheckBox
扫一扫加微信
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网