how do I reference the current datarow from a datagrid?

kilobyte

Newcomer
Joined
Sep 10, 2003
Messages
8
Hi

I'm making a windows app which displays a datagrid. This datagrid has a dataset as its datasource. So far quite simple.

My problem is I don't know how to get a reference to the 'current' datarow from the datagrid. I can get the CurrentRowIndex, but this does not necesarrily correspond to the index in the dataset, because rows can have been deleted, or the datagrid might be sorted etc.

I'm thinking I can extract an id from the datagrid row, and find the corresponding row in the dataset. But to me this seems to be a sort of roundabout way of doing it. Is there really no better way to do it?

I've been looking at the BindingContext, but so far haven't been able to come up with anything good.

I hope someone can help me with this annoying problem!

Martin N Jensen
 
I'd say go to 4guysfromrolla.com.
There's a comprehensive Datagrid tutorial from Scott Mitchell. That might your answer.
 
Yea, I did the thing with the id now, and that works alright. It still feels like a bit of a roundabout way of doing it though.
 
Back
Top