English 中文(简体)
数据单 观点核对栏“显示所有”业绩
原标题:DataGridView checkbox column "select all" performance

我有一个带有检查箱子的《数据集》。 我试图创建一种选择/选择所有纽州。 改变这些价值观的守则是十分容易的,但业绩是可怕的。

for (int i = 0; i < dgv.RowCount; i++)
{
    dgv.Rows[i].Cells["Selected"].Value = _selectAll;
}

选择所有人只是一个角球 b变。 在业绩迅速的情况下,是否有更好的办法做到这一点? 我试图改变基本数据表的价值。 仅剩下几百个段落,但大多数工作将在数千个行中进行。

<EDIT & SOLUTION (2011/10/4)

主要问题是DGV的特性。 一俟我确定,

dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;

performance improved dramatically (per MSDN DataGridView Performance). The solutions suggested as of this edit would also improve performance slightly.

最佳回答

抽签决定了<代码> AutoSizeColumnsMode 财产

dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;

业绩更好......

问题回答

Well, this is a common problem.
First, do you have any processing associated with the Checkbox checked change?
If so, create a bool member variable.
Initialize it to false before performing the Select All / Deselect All.
In the CheckBox checked change event -> check for the value of the bool paramter.
If it comes with false return from the event. Dont process anything.
After completing the for looping to set the select all / Deselect All, process the checked change event if necessary.
Dont forget to reset the bool parameter to true after for loop.

bool _allowProcessing = false;
//SelectAll / Deselect All
for (int i = 0; i < dgv.RowCount; i++)
{
   dgv.Rows[i].Cells[4].Value = _selectAll;
}
_allowProcessing = true;
// Do some processing if required

// Checked change event
public void CheckBox_CheckedChange(object sender, eventArgs e)
{
  if(!_allowProcessing)
    return;

  // Do Processing
}

如果你不能够提高业绩,但你可以尝试:

for (int i = 0; i < dgv.RowCount; i++)
{
    dgv["Selected", i].Value = _selectAll;
}

u 不能给出电网名称,而是可以具体说明它属于哪一栏。 这将加快工作。 希望会有所助益。

for (int i = 0; i < dgv.RowCount; i++)
{
   dgv.Rows[i].Cells[4].Value = _selectAll;
}

I show another way to improve this problem.
Accessing datagridview directly like dgv.Rows[i].Cells["Selected"].Value makes datagridview slowly.

因此,如果你的数据网格有数据来源,而且数据来源已经核实了现状,那么数据来源和复读数据网的概览就能够取得更好的业绩。

foreach (var item in yourDataSource)
{
    item.Checked = _selectAll;
}
dgv.Invalidate();




相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签