all groups > dotnet windows forms databinding > september 2007 >
You're in the

dotnet windows forms databinding

group:

datagridview data



datagridview data radiolandog
9/23/2007 5:09:12 PM
dotnet windows forms databinding: C# - VS2005 - windows form app
child form has a dataGridView control that displays a table

when a row is clicked I would like to return the value in one column (the
primary key) to the parent form

how do I access the data in a particular column in the current row?

I can find the current row - myDataGridView.CurrentRow.Index.
How can I reference a particular column (the first column) and retrieve the
data???

Thanks,
-dog



RE: datagridview data v-lliu NO[at]SPAM online.microsoft.com
9/24/2007 2:55:27 AM
Hi,

You can use the Cells property of the DataGridViewRow class to get the
value of a specified column within a DataGridViewRow.

For example, the following line of code gets the value of the first column
of the current row in a DataGridView:

object cellvalue = this.dataGridView1.CurrentRow.Cells[0].Value;

-or-
// if the column name is "ID"
object cellvalue = this.dataGridView1.CurrentRow.Cells["ID"].Value;

Hope this helps.
If you have anything unclear, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Re: datagridview data radiolandog
9/24/2007 5:00:08 PM
The first way worked, thanks.

The second way gives an error that "Column named myColumn cannot be
found." - when there is a column with that name in the table and in the
DataGridView control.

Any ideas as to why???

Thanks, -dog


[quoted text, click to view]

Re: datagridview data v-lliu NO[at]SPAM online.microsoft.com
9/25/2007 12:00:00 AM
Hi,

Thank you for your reply!

[quoted text, click to view]
found."

It seems that the column named myColumn doesn't exist in your DataGridView.

You have two options to check the name of a DataGridViewColumn.

Option 1:

1. Switch to the form designer and select the DataGridView on the form.

2. Click the smart tag glyph on the top-right corner of the DataGridView
and the smart tag panel appears. Click the 'Edit Columns' command in the
smart tag panel and the 'Edit Columns' dialog pops up.

3. In the 'Edit Columns' dialog, select a column in the list on the left
hand and the name of this column is displayed in the Name entry within the
properties window on the right hand.

Option 2:

Use the following line of code to get the name of a specified column:

// get the name of the first column
string coulmnName = this.dataGridView1.Columns[0].Name;

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support
Re: datagridview data radiolandog
9/26/2007 3:10:56 PM
I learned that it is named "myColumnDataGridViewTextBoxColumn" -- who knew??

Thanks...



[quoted text, click to view]

Re: datagridview data Lee Morris
10/11/2007 12:04:23 PM

Linda
I was struggling with the same problem. I was using the column name from
the database. Your trick of using the datagridview glyph helped alot.
Thanks!
Lee


AddThis Social Bookmark Button