datagrid row <--> datasetrow

Z

Zürcher See

If I know the datagrid row there is a method to get the dataset row?

Now I use the dataset id the find it out,

id=this.dataGrid1[this.dataGrid1.CurrentRowIndex,0]; // column 0 is id

DataRow drRow=this.dataSet1.Tables["Table"].Rows.Find(id);

but I don't like it very much, there is a "cleaner" way the get the dataset
row?
 
N

Nicholas Paldino [.NET/C# MVP]

Zurcher,

The data grid is really bound to the view on the data. If you bound to
a data table, then the DefaultView property exposes the DataView that the
grid binds to. You will want to get the row number in the grid, and then
get the appropriate row through the DataView object.

Hope this helps.
 
Z

Zürcher See

You means something like:


Nicholas Paldino said:
Zurcher,

The data grid is really bound to the view on the data. If you bound to
a data table, then the DefaultView property exposes the DataView that the
grid binds to. You will want to get the row number in the grid, and then
get the appropriate row through the DataView object.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Zürcher See said:
If I know the datagrid row there is a method to get the dataset row?

Now I use the dataset id the find it out,

id=this.dataGrid1[this.dataGrid1.CurrentRowIndex,0]; // column 0 is id

DataRow drRow=this.dataSet1.Tables["Table"].Rows.Find(id);

but I don't like it very much, there is a "cleaner" way the get the dataset
row?
 
Z

Zürcher See

I tried something like:

DataRow
drRow=this.dataSet1.Tables["Table"].DefaultView[this.dataGrid1.CurrentRowInd
ex].Row;

but this does not work

Nicholas Paldino said:
Zurcher,

The data grid is really bound to the view on the data. If you bound to
a data table, then the DefaultView property exposes the DataView that the
grid binds to. You will want to get the row number in the grid, and then
get the appropriate row through the DataView object.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Zürcher See said:
If I know the datagrid row there is a method to get the dataset row?

Now I use the dataset id the find it out,

id=this.dataGrid1[this.dataGrid1.CurrentRowIndex,0]; // column 0 is id

DataRow drRow=this.dataSet1.Tables["Table"].Rows.Find(id);

but I don't like it very much, there is a "cleaner" way the get the dataset
row?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top