Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Current row index

Status
Not open for further replies.

bbegley

Programmer
Apr 29, 2002
228
US
How can I refer to additional data in a selected record? It appears that in order to get the data in a field, I need to know the index number for that row, and yet it does not appear that the index number for a row is something that is readily available.

In Delphi, I would do something like this:

StringS := Table1.FieldByName('Field1').AsString;

How do I get the value of a field based upon the selected row.

If someone can answer this, I have an additional difficulty. It appears that the data binding for a datagrid does not necessarily match that of the form itself. If I tie the form and grid bindings together on each cell change for the grid, it works until someone clicks on a grid column and sorts the grid. Is there a way to tell how the grid row corresponds to the forms row?

Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
I thought fields in a row were accessible either by index OR name...

Code:
DataRow row  = myDataTable.Rows[0];

string s = row["Column1"].Value.ToString();
//same as
string s = row[0].Value.ToString();

is that not what you are talking about? Or are you wondering how to get a reference to a particular ROW in the table without knowing it's index?

I almost always loop through the table and check eash row if looking for a praticular value. is that what you look for?

HTH

David
[pipe]
 
Thanks for the reply.

I guess my confusion stems from the idea that what seems like a one line thing to me is not one line here. An object(row) must be instantiated, the record located, and the value ascertained.

It seems to me that the object already exists (within the Dataset) and with the record already selected by the user, that the value should be accessible.

It seems like there a lot of different ways to do everything in .NET, I was just hoping that there was a more obvious way to do this.

It looks like I will create classes to encapsulate the desired functionality, but it seems to me that nearly everyone else has to do so also.

Do you have a way to reconcile the datagrid record index with the form.bindingcontext index, particularly after the grid is sorted?

Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
You COULD do it in one line, I was just trying to be more clear
Code:
string s = myDataSet.Tables[0].Rows[0]["Column"].ToString();
(forget the Value item, I think that's wrong)

Sorry I don't have an answer for the second part of your question...

HTH


David
[pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top