D
David
Hello.
I have some little problem with DataSet and I hope somebody will help me.
So what's my problem:
I have DataSet with some table in it lets say table name is "Suppliers", I
have DataGrid to show the records from this DataSet and toolbar
fornavigating and editing rows in DataSet.
I'm using another form for editing data and the manualy update it to
DataSet.
I wrote this code in toolBar ButtonClick event:
private void toolBar_ButtonClick(object sender,
System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
// Getting clicked button index
int buttonIndex = toolBar.Buttons.IndexOf(e.Button);
// Get the BindingManagerBase for the DataGrid useing the DataGrid
instance
BindingManagerBase bm = myGrid.BindingContext[myGrid.DataSource];
// Evaluate the Button property to determine which button was clicked
if (bm.Position != -1)
switch(buttonIndex)
{
case 0:
// Move to first record (customer)
bm.Position = 0;
break;
case 1:
// Move to previous record (customer)
bm.Position -= 1;
break;
case 2:
// Move to next record (customer)
bm.Position += 1;
break;
case 3:
// Move to last record (customer)
bm.Position = bm.Count -1;
break;
case 5:
// Edit selected record (customer)
EditSupplier(myDataDS.Tables["Suppliers"].Rows[bm.Position]);
break;
case 6:
// Prompt user to delete selected record (customer)
if (MessageBox.Show("Do you want to delete selected record?",
"Confirmation",
MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2) == DialogResult.Yes)
{
// Delete selected record (customer)
bm.RemoveAt(bm.Position);
}
break;
}
}
So, what's a proble after I delete some row or rows in DataSet and then try
to access some row which is after that row I have just deleted (for
accessing row I wrote
myDataDS.Tables["Suppliers"].Rows[bm.Position]["SomeField"]) in the DataSet,
there is exception with message: "Deleted row information cannot be accessed
through the row".
I thin EditSupplier(myDataDS.Tables["Suppliers"].Rows[bm.Position]); is not
rihgt, but how can I send to function the current row of DataSet?
I have some little problem with DataSet and I hope somebody will help me.
So what's my problem:
I have DataSet with some table in it lets say table name is "Suppliers", I
have DataGrid to show the records from this DataSet and toolbar
fornavigating and editing rows in DataSet.
I'm using another form for editing data and the manualy update it to
DataSet.
I wrote this code in toolBar ButtonClick event:
private void toolBar_ButtonClick(object sender,
System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
// Getting clicked button index
int buttonIndex = toolBar.Buttons.IndexOf(e.Button);
// Get the BindingManagerBase for the DataGrid useing the DataGrid
instance
BindingManagerBase bm = myGrid.BindingContext[myGrid.DataSource];
// Evaluate the Button property to determine which button was clicked
if (bm.Position != -1)
switch(buttonIndex)
{
case 0:
// Move to first record (customer)
bm.Position = 0;
break;
case 1:
// Move to previous record (customer)
bm.Position -= 1;
break;
case 2:
// Move to next record (customer)
bm.Position += 1;
break;
case 3:
// Move to last record (customer)
bm.Position = bm.Count -1;
break;
case 5:
// Edit selected record (customer)
EditSupplier(myDataDS.Tables["Suppliers"].Rows[bm.Position]);
break;
case 6:
// Prompt user to delete selected record (customer)
if (MessageBox.Show("Do you want to delete selected record?",
"Confirmation",
MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2) == DialogResult.Yes)
{
// Delete selected record (customer)
bm.RemoveAt(bm.Position);
}
break;
}
}
So, what's a proble after I delete some row or rows in DataSet and then try
to access some row which is after that row I have just deleted (for
accessing row I wrote
myDataDS.Tables["Suppliers"].Rows[bm.Position]["SomeField"]) in the DataSet,
there is exception with message: "Deleted row information cannot be accessed
through the row".
I thin EditSupplier(myDataDS.Tables["Suppliers"].Rows[bm.Position]); is not
rihgt, but how can I send to function the current row of DataSet?