473,327 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Pick DataGrid column value

RP
I want to pick a column value as the user selects a row of the
DataGrid.

Aug 14 '07 #1
5 2485
On Tue, 14 Aug 2007 16:42:49 +0200, RP <rp*********@gmail.comwrote:
I want to pick a column value as the user selects a row of the
DataGrid.

Depending on the DataSource you should be able to get this information using DataGrid.CurrentCell/CurrentRowIndex.

If you use a DataGridView, you can also use DataGridView.CurrentRow.Cells[columnindex]

You can also get this information using DataBinding

--
Happy coding!
Morten Wennevik [C# MVP]
Aug 14 '07 #2
RP
CurrentCell retrieves information of the selected cell in a column.
What I want is that when an entire row is selected, say when I select
row 3 then I want to value of column 2.
On Aug 14, 7:56 pm, "Morten Wennevik [C# MVP]"
<MortenWenne...@hotmail.comwrote:
>
Depending on the DataSource you should be able to get this information using DataGrid.CurrentCell/CurrentRowIndex.

If you use a DataGridView, you can also use DataGridView.CurrentRow.Cells[columnindex]

You can also get this information using DataBinding

--
Happy coding!
Morten Wennevik [C# MVP]

Aug 14 '07 #3
On Tue, 14 Aug 2007 17:16:33 +0200, RP <rp*********@gmail.comwrote:
CurrentCell retrieves information of the selected cell in a column.
What I want is that when an entire row is selected, say when I select
row 3 then I want to value of column 2.
On Aug 14, 7:56 pm, "Morten Wennevik [C# MVP]"
<MortenWenne...@hotmail.comwrote:
>>
Depending on the DataSource you should be able to get this information using DataGrid.CurrentCell/CurrentRowIndex.

If you use a DataGridView, you can also use DataGridView.CurrentRow.Cells[columnindex]

You can also get this information using DataBinding

--
Happy coding!
Morten Wennevik [C# MVP]


Well, using a DataGrid I think you need to look up the values from the DataSource. If you can, use DataGridView instead.

--
Happy coding!
Morten Wennevik [C# MVP]
Aug 14 '07 #4
RP wrote:
CurrentCell retrieves information of the selected cell in a column.
What I want is that when an entire row is selected, say when I select
row 3 then I want to value of column 2.
You can use the Cells collection in the CurrentRow object for this. It's
probably better to get the actual DataSource information but if you
absolutely have to have what's in the grid this is the way to do it:

someVar = yourDataGridView.CurrentRow.Cells["someColumn"].Value;
There may be other/better ways to retrieve a particular column in the
currently selected Row, but I've used the above method in several places.
Chris.
Aug 14 '07 #5
Chris Shepherd wrote:
RP wrote:
>CurrentCell retrieves information of the selected cell in a column.
What I want is that when an entire row is selected, say when I select
row 3 then I want to value of column 2.

You can use the Cells collection in the CurrentRow object for this. It's
probably better to get the actual DataSource information but if you
absolutely have to have what's in the grid this is the way to do it:

someVar = yourDataGridView.CurrentRow.Cells["someColumn"].Value;
There may be other/better ways to retrieve a particular column in the
currently selected Row, but I've used the above method in several places.
*Smacks self with the read-entire-thread-before-replying stick*

Chris.
Aug 14 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jean Carlo | last post by:
Hello guys I`m developing a windows form that contain one Datagrid. In this datagrid I insert a checkBox Column. I need to get all rows where checkbox is checked by user. How do I get this...
3
by: PeterZ | last post by:
G'day, After doing much searching and pinching bits of ideas from here there and everywhere I came up with a fairly 'clean' solution of including a comboBox into a dataGrid column. You can...
0
by: Amber | last post by:
There are times when you will need to highlight or otherwise modify the contents of a particular DataGrid row-column value based upon the value in the column. In this example we will select the...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
2
by: CSL | last post by:
I am using the DataGrid in a Windows Application, how can I adjust the widths of each column individually.
1
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get...
1
by: jimb | last post by:
I can get the dropdownlist into the datagrid, and I can populate it, but I can't read it. Anybody have a working example of a dropdownlist in an editable grid? Thanks. -- .....
6
by: Agnes | last post by:
I understand it is impossible, but still curious to know "Can I freeze several column in the datagrid, the user can only scroll the first 3 columns (not verical), for the rest of the coulumn, it is...
4
by: Anthony | last post by:
Hi Folks, I'm adding some columns to my datagrid which are of Combo Box type. I'm inheriting DataGridTextBoxColumn and doing all the usual stuff to get them populated. This is working fine. I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.