Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > get a field value from a dbgrid
 

get a field value from a dbgrid

I do not know why Microsoft has to make everything so complicated by my lord. All I want is the value from a specific field (column) in a dbgrid that is currently selected and after 4 hours of digging through books and good I've found nothing. Its like no one has ever had to do such a silly thing before.

To be clear: I have a grid. It has 3 records in it. I select the 2nd row and I want a message box to popup and tell me the contactID # from that selected field. ContactID is just a field in the grid...

Can anyone help me?

Thanks,

glenn

cybercrypt13  Thursday, March 22, 2007 3:35 AM

Hi,

Handle  Cell_click event of DataGridView and implement it as follows

[Code language = C#]

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)

        {

            MessageBox.Show(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());           

        }   

      

[/Code]

 

 

This will give u,what u wanted.

 

Thanx,

Ch.T.Gopi Kumar.

 

TilakGopi  Thursday, March 22, 2007 6:51 AM

Hi,

Handle  Cell_click event of DataGridView and implement it as follows

[Code language = C#]

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)

        {

            MessageBox.Show(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());           

        }   

      

[/Code]

 

 

This will give u,what u wanted.

 

Thanx,

Ch.T.Gopi Kumar.

 

TilakGopi  Thursday, March 22, 2007 6:51 AM

You can use google to search for other answers

Custom Search

More Threads

• Could you help me in these questions, please?
• problem with data binding
• DataGridView Inital View Does Not Display Correctly
• Converting to the correct type in a Binded ArrayList
• Displaying the next item in a data table
• DataGridView.Focused ?????
• Error while accessing value of the control
• validate DataGrid bound to Array
• Check the checkbox in a datagridview
• comboBox problem