DataSet Problem

  • Thread starter Thread starter David
  • Start date Start date
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?
 
That's a common mistake - to use grid's index on DataTable instead of using
it on DataView grid is bound to.

Please see this for more details:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=y6XsU1GhDHA.456%4
0cpmsftngxa06.phx.gbl&rnum=1&prev=/groups%3Fq%3DIlya%2BTumanov%2Bdelete%2Bro
w%2Bgroup:microsoft.public.dotnet.framework.compactframework%26hl%3Den%26lr%
3D%26ie%3DUTF-8%26group%3Dmicrosoft.public.dotnet.framework.compactframework
%26selm%3Dy6XsU1GhDHA.456%2540cpmsftngxa06.phx.gbl%26rnum%3D1

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Reply-To: "David" <[email protected]>
From: "David" <[email protected]>
Subject: DataSet Problem
Date: Thu, 12 Aug 2004 13:42:16 +0400
Lines: 72
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Message-ID: <O#[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: ge-tbs-ats77-tc-ppp2.wanex.net 213.131.38.163
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.compactframework:59227
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

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?
 
Can you show me some examples please?

"Ilya Tumanov [MS]" said:
That's a common mistake - to use grid's index on DataTable instead of using
it on DataView grid is bound to.

Please see this for more details:

http://groups.google.com/groups?hl=...soft.public.dotnet.framework.compactframework
%26selm%3Dy6XsU1GhDHA.456%2540cpmsftngxa06.phx.gbl%26rnum%3D1

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Reply-To: "David" <[email protected]>
From: "David" <[email protected]>
Subject: DataSet Problem
Date: Thu, 12 Aug 2004 13:42:16 +0400
Lines: 72
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Message-ID: <O#[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: ge-tbs-ats77-tc-ppp2.wanex.net 213.131.38.163
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.compactframework:59227
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

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?
 
Already did. Just follow provided link and read entire thread. You'll find
a sample in the last message.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Reply-To: "David" <[email protected]>
From: "David" <[email protected]>
References: <O#[email protected]>
Subject: Re: DataSet Problem
Date: Fri, 13 Aug 2004 10:21:02 +0400
Lines: 126
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Message-ID: <#[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: ge-tbs-ats77-tc-ppp4.wanex.net 213.131.38.165
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.compactframework:59299
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

Can you show me some examples please?

"Ilya Tumanov [MS]" said:
That's a common mistake - to use grid's index on DataTable instead of using
it on DataView grid is bound to.

Please see this for more details:
http://groups.google.com/groups?hl=...soft.public.dotnet.framework.compactframework
%26selm%3Dy6XsU1GhDHA.456%2540cpmsftngxa06.phx.gbl%26rnum%3D1

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
"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?
 
Back
Top