By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,467 Members | 1,493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,467 IT Pros & Developers. It's quick & easy.

Changing bit values in DataTable?

P: n/a
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
Mar 30 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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();

Mar 31 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.