我面临的问题与http://www.windows-tech.info/3/fc05dcdb57f27f48.php完全相同,但是,那里描述的解决方法对我不起作用(除非我误解了它)。
我有一个DataGridView
,它绑定到DataTable
,并且还有ComboBox
列(根据上面链接中的用户,这很重要)。我试图根据单独的DataGridView
过滤此ComboBox
,但是一旦我这样做,就会变得无法接受。
目前我在ComboBox
更改事件中有这个:
private void cmbFilter_SelectedIndexChanged(object sender, EventArgs e)
{
(dgvVolReport.DataSource as DataTable).DefaultView.RowFilter = string.Empty;
}
所以我甚至没有过滤,甚至只是将.RowFilter
设置为string .Empty
会让它变慢。
有没有人知道这件事,如何解决或解决方法?
更新:奇怪的是,如果我打电话给这一行:
((DataTable)((DataGridView)sender).DataSource).DefaultView.RowFilter = string.Empty;
在我的CellEndEdit
事件中,只要ComboBox
SelectedIndexChanged
中的那一行不存在,它就不会变慢。所以它似乎是影响性能的外部ComboBox
。也许它经常触发?
答案 0 :(得分:3)
It's possible that your column auto-sizing is slowing you down if you have too many rows for the UI to cycle through. If you have the below setting (programmatically or in properties) then you might want to change settings. Try none. If that's fast, set it to use headings or only visible cells.
detailsDataGridView.AutoSizeColumnsMode =
DataGridViewAutoSizeColumnsMode.AllCells;
I'm not sure that's affecting you, though. It seems like the SelectedIndexChanged is being called too often. If you set DisplayMember
and ValueMember
after setting the datasource
, this can happen because it will call theSelectedIndexChanged event those times which is then iterating through your whole table again.
You could also use the ComboBox.SelectionChangeCommitted
Event, which is less sensitive to things like databinding where you might not be expecting the event to fire.