Retrieve the value from two cells from a row in a dataGridView, C#2005Expr

Anyone  who know how to retrieve the value from two cells when you click a row in a dataGridView so you can insert the values in two variables

Observe! It doesn't seem to work in the way it did in earlier versions of VS.NET - I've tried but it didn't work (but from earlier experiences I know that's not a garanti tough). I know how to retrieve the value from the cell you click in, but since I have two key attributes in the table that's visualized in the dataGridView I also need to retrieve both values to be able to delete or update a row/tuple.

Anyone who knows when Microsoft is going to hand out this kind of information

Regards,
//Nick :o)


Answer this question

Retrieve the value from two cells from a row in a dataGridView, C#2005Expr

  • Glennpd

    Hi friends,

    I am new to C#, i am using DataGridView and VS 2005. I tried to place the tooltips on datagridview control.. So I override CellFormatting event of DataGrdview and i write the code like this.

    private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)

    {

    DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];

    cell.ToolTipText = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();

    }

    It showing tooltip only on the cells not in the column headers,, Can u anybody tell me how to place tooltip on columns of DataGrdview

    Reply me


  • Ajil

    Hi!

    In an earlier application, in VS.NET 2003 i added this code to get the function I wanted:

    private void dataGrid1_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne)
    {
       dataGrid1 .CurrentCell =
    new DataGridCell(dataGrid1.CurrentRowIndex, 0);
    }

    I tried to do the same in VC#2005Expr but then I recieve following message:

    "Cannot implicitly convert type 'System.Windows.Forms.DataGridCell' to 'System.Windows.Forms.DataGridViewCell'"

    So there's the problem - type convertion, but what class should I use then

    //Nick



  • Bri68

    The EventArgs e variable contains the RowIndex you are on which would make the above code even simpler.

    Dave C

  • JB-Bellevue

    he asked you a friggin question on how YOUR product works.

    why shoukd he have to present a sample

    if you dont know u should say so.

    the half baked documentation and public beta testing is going to kill this product


  • ryan_gartner

    So, finally I found out how to do it in C#. It was not very obvious!

    < xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
    textBox1.Text = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells["DayInfo"].Value.ToString();
    }


     


    You can now click on the value in any column and you retrieve the value from the column "DayInfo" from the same row.


  • Kevin_H

    Hi,

    I'm moving this post to .NET Development General.

    Could you post a code snippet on how you tried to retrieve the values
    And also, provide steps that could reproduce your situation...

     

     

    cheers,

    Paul June A. Domag



  • Retrieve the value from two cells from a row in a dataGridView, C#2005Expr