Changing bit values in DataTable?

  • Thread starter Thread starter Tim Cowan
  • Start date Start date
T

Tim Cowan

Hi,

I was wondering if there is a quicker way to do this? I have a select all
check box for data in a grid and when checked I want the checkboxes in the
grid to be checked.

I am currently using:

foreach(DataRowView DRV in dvData)
{
DRV["BIT_print_label"] = this.chkSelectAll.Checked;
}

It is very slow for a large amount of data, approx 1888 records. Can anyone
suggest a faster way. I am using VS2005.

Tim
 
Tim,

I did as simple test which took about 0.5 seconds to run using this.

DataTable dataTable = dvData.Table;
dataTable.BeginLoadData();

bool checkedValue = this.chkSelectAll.Checked;
int labelCol = dvData.Table.Columns.IndexOf("BIT_print_label");
foreach(DataRowView DRV in dvData)
{
DRV[labelCol] = checkedValue;
}
dataTable.EndLoadData();

It does some simple caching. I'm not sure why your code is taking so
long to run?
Do have any events such as RowChanging or ColumnChanging that are being
fired?

Are you using a grid that's redrawing itself as you change each record?

You might also consider filtering the DataTable using SELECT to get
those that need BIT_print_label changing:
DataTable dataTable = dvData.Table;
dataTable.BeginLoadData();

bool checkedValue = this.chkSelectAll.Checked;
DataRow[] changes = dataTable.Select("BIT_print_label = " + (!
checkedValue));
int labelCol = dvData.Table.Columns.IndexOf("BIT_print_label");
foreach(DataRow row in changes)
{
row[labelCol] = checkedValue;
}
dataTable.EndLoadData();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top