A
Alex Vary
Guest
Hi Forum,
I have a problem with a form that has 2 listboxes, both bound to the same DataTable, just with different filter values. I filter on 1 column. I load this DataTable from a database and my plan is to write it back to the db after changes are done.
My idea is to move values from the first to the second listbox with a button. That click-event changes the above mentioned filter from 0 to 1. With that the selected row moves as expected.
The problem is, if I select multiple rows, it takes very long (like 1,5 seconds for 5 rows) to be moved.
After I googled this I found a solution to add a DataRow.BeginEdit() before I change the values. That also works, but requires a DataTable.AcceptChanges() after all changes are done. That unfortunately causes the RowState-Properties to change to "Unchanged", so I cant write it back to the database (I am using a DataAdapter for that).
Any ideas how to have both performance and still use DataAdapter.Update(DataTable)?
Loading the values
DataSet licenses = bLogic.GetLicenses(9999);
DataColumn[] pk = new DataColumn[1];
pk[0] = licenses.Tables[0].Columns[0];
licenses.Tables[0].PrimaryKey = pk;
lbxAvailable.DataSource = new DataView(licenses.Tables[0], "LicenseNeeded = 0", "DisplayName", DataViewRowState.CurrentRows);
lbxAvailable.DisplayMember = "FullName";
lbxAvailable.ValueMember = "ProgID";
lbxSelected.DataSource = new DataView(licenses.Tables[0], "LicenseNeeded = 1", "DisplayName", DataViewRowState.CurrentRows);
lbxSelected.DisplayMember = "FullName";
lbxSelected.ValueMember = "ProgID";
Change values and call business logic to save to db
string addValues = "";
string[] addings = new string[lbxAvailable.SelectedItems.Count];
int i = 0;
foreach (object item in lbxAvailable.SelectedItems)
{
addValues += ((DataRowView)item).Row.ItemArray[0].ToString() + ",";
i++;
}
addValues = addValues.Substring(0, addValues.Length - 1);
DataRow[] dr = licenses.Tables[0].Select("ProgID in (" + addValues + ")");
for (int j = 0; j <= addings.GetUpperBound(0); j++)
{
//dr[j].BeginEdit(); // very slow without this
dr[j]["LicenseNeeded"] = 1;
}
//licenses.Tables[0].AcceptChanges(); // needed because of use of BeginEdit()
bLogic.SaveLicenses(licenses, out innerError);
TIA
Alex
Continue reading...
I have a problem with a form that has 2 listboxes, both bound to the same DataTable, just with different filter values. I filter on 1 column. I load this DataTable from a database and my plan is to write it back to the db after changes are done.
My idea is to move values from the first to the second listbox with a button. That click-event changes the above mentioned filter from 0 to 1. With that the selected row moves as expected.
The problem is, if I select multiple rows, it takes very long (like 1,5 seconds for 5 rows) to be moved.
After I googled this I found a solution to add a DataRow.BeginEdit() before I change the values. That also works, but requires a DataTable.AcceptChanges() after all changes are done. That unfortunately causes the RowState-Properties to change to "Unchanged", so I cant write it back to the database (I am using a DataAdapter for that).
Any ideas how to have both performance and still use DataAdapter.Update(DataTable)?
Loading the values
DataSet licenses = bLogic.GetLicenses(9999);
DataColumn[] pk = new DataColumn[1];
pk[0] = licenses.Tables[0].Columns[0];
licenses.Tables[0].PrimaryKey = pk;
lbxAvailable.DataSource = new DataView(licenses.Tables[0], "LicenseNeeded = 0", "DisplayName", DataViewRowState.CurrentRows);
lbxAvailable.DisplayMember = "FullName";
lbxAvailable.ValueMember = "ProgID";
lbxSelected.DataSource = new DataView(licenses.Tables[0], "LicenseNeeded = 1", "DisplayName", DataViewRowState.CurrentRows);
lbxSelected.DisplayMember = "FullName";
lbxSelected.ValueMember = "ProgID";
Change values and call business logic to save to db
string addValues = "";
string[] addings = new string[lbxAvailable.SelectedItems.Count];
int i = 0;
foreach (object item in lbxAvailable.SelectedItems)
{
addValues += ((DataRowView)item).Row.ItemArray[0].ToString() + ",";
i++;
}
addValues = addValues.Substring(0, addValues.Length - 1);
DataRow[] dr = licenses.Tables[0].Select("ProgID in (" + addValues + ")");
for (int j = 0; j <= addings.GetUpperBound(0); j++)
{
//dr[j].BeginEdit(); // very slow without this
dr[j]["LicenseNeeded"] = 1;
}
//licenses.Tables[0].AcceptChanges(); // needed because of use of BeginEdit()
bLogic.SaveLicenses(licenses, out innerError);
TIA
Alex
Continue reading...