471,315 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,315 software developers and data experts.

DataGrid Question

C# .NET 1.1

I have a datagrid bound to a dataset.
this.dgMyData.SetDataBinding(this._dataSet, "SomeData");

After I select multiple rows how do I access the data from the selected
rows?

Thank You
Peter
Feb 8 '06 #1
3 1657
Hi Peter,

To get a single row that is selected, please use the CurrencyManager like:

CurrencyManager cm =
(CurrencyManager)this.dbMyData.BindingContext[this._dataSet, "SomeData"];

cm.Current is the selected row.

If you need to get all the seleted rows, you have to go through all the
rows on the grid and use IsSelected method to check if that row is
selected. Here is an example:

for(int i=0;i<this.dataGrid1.VisibleRowCount;i++)
{
if(this.dataGrid1.IsSelected(i))
MessageBox.Show("Row "+i.ToString());
}

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Feb 8 '06 #2

"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:DO***************@TK2MSFTNGXA01.phx.gbl...
Hi Peter,

To get a single row that is selected, please use the CurrencyManager like:

CurrencyManager cm =
(CurrencyManager)this.dbMyData.BindingContext[this._dataSet, "SomeData"];

cm.Current is the selected row.

If you need to get all the seleted rows, you have to go through all the
rows on the grid and use IsSelected method to check if that row is
selected. Here is an example:

for(int i=0;i<this.dataGrid1.VisibleRowCount;i++)
{
if(this.dataGrid1.IsSelected(i))
MessageBox.Show("Row "+i.ToString());
}

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."


That's what I needed

Thank You
Feb 8 '06 #3
You're welcome!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Feb 9 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Randy | last post: by
2 posts views Thread by pei_world | last post: by
3 posts views Thread by Danky | last post: by
4 posts views Thread by Jan Nielsen | last post: by
13 posts views Thread by pmcguire | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.