bpeterson
bpeterson

Reputation: 3

C# - Get selected cell's row's first cell's value

My question sounds pretty weird, but my problem is that I don't know how to get a selected cell's row's FIRST cell's value.

For example:

column1 column2 column3 item1 item2 item3

Let's say I select item2, now how could I get item1's value?

Thanks!

Upvotes: 0

Views: 4043

Answers (2)

zanlok
zanlok

Reputation: 1630

This is a Javascript answer.

You've got a C# flag here, but this almost sounds more like raw Javascript on the client. If so, navigating the DOM tree gets pretty easy if you use a library such as Prototype. If this is what you're after, check the quick code below. If it's a numerical value you're after, check this post.

this_td.up('td');

Keep looping "up" the td until you hit the end. Alternatively, you can just instrument the ID of all cells such that it's easy to figure out the first cell's id, and traverse straight to that cell via $("cell_name_12345"). That would be if you want the "name" column, and you're in the "phone" column with an id of "cell_phone_12345", if you know what I mean.

Upvotes: 0

TreDubZedd
TreDubZedd

Reputation: 2556

I assume you're using a DataGridView? If so, look at the DataGridView.SelectedRow.Cells[0].

Upvotes: 1

Related Questions