locked
Obtaining cell value from DataGridView on double click RRS feed

  • Question

  • Hello,

    if I move the cursor over DataGridView cells with a lot of text, I get the whole content displayed by the tooltip for some seconds.

    Now I want to display the whole content of a DataGridView cell in an extra Windows Form by double-clicking on it.

    How can I achieve this in C#?

    Thanks

    Axel

    Tuesday, September 14, 2010 3:13 PM

Answers

  • For example:

    On Form1 on a doublClick on a cell you get the string:

        string myValue;
        private void dataGridView2_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
          myValue = dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
          Form2 = new Form2(myValue); //you pass it to Form2
        }  
    
    
    

    ... which you pass it to Form2 and display it there in a label:

      public class Form2
      {
        string myString;
        Label label1;
        public Form2(string _myString)
        {
          InitializeComponent();
          myString = _myString;
        }
    
        private void CreatingLabel()
        {
          label1 = new Label();
          label1.Location = new Point(10, 20);
          label1.Text = myString;      
        }
      }  
    

    The text from a cell in now in a label on Form2!

    I hope I was helpful, if not ask again

    Mitja

    • Marked as answer by ax123 Wednesday, September 15, 2010 6:38 AM
    Tuesday, September 14, 2010 3:52 PM

All replies

  • For example:

    On Form1 on a doublClick on a cell you get the string:

        string myValue;
        private void dataGridView2_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
          myValue = dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
          Form2 = new Form2(myValue); //you pass it to Form2
        }  
    
    
    

    ... which you pass it to Form2 and display it there in a label:

      public class Form2
      {
        string myString;
        Label label1;
        public Form2(string _myString)
        {
          InitializeComponent();
          myString = _myString;
        }
    
        private void CreatingLabel()
        {
          label1 = new Label();
          label1.Location = new Point(10, 20);
          label1.Text = myString;      
        }
      }  
    

    The text from a cell in now in a label on Form2!

    I hope I was helpful, if not ask again

    Mitja

    • Marked as answer by ax123 Wednesday, September 15, 2010 6:38 AM
    Tuesday, September 14, 2010 3:52 PM
  • Hi Mitja,

    very well done!

    Wednesday, September 15, 2010 6:38 AM