OnClick DataGrid

Ok probably been asked hundreds of times but the answer I found could not help me :(
I'm using Visual Studios 2005. I have a DataGrid in a WindowsApplication. Basically when I click a cell I want to get what the cell contains and put it in to a veritable. If you can help me then pleas do kind of stuck….




Answer this question

OnClick DataGrid

  • logtorahul

    THANK YOU you just made my day


  • lm4242

    In Visual Studio 2005 you can use the DataGridView and then use the CellClick event to get the value:


    private void dataGridView1_CellClick( object sender, DataGridViewCellEventArgs e )
    {
    DataGridViewCell cell = dataGridView1.Rows[ e.RowIndex ].Cells[ e.ColumnIndex ];
    MessageBox.Show( this, "Selected value is " + cell.Value );
    }



    If you want to get more information about the DataGridView you should read: Introducing a New Data Grid.

    You can use the normall old DataGrid, but then you need to do a HitTest in the MouseUp event.


  • OnClick DataGrid