locked
How Can I Make a DataGridView Row/Cell Selected? RRS feed

  • Question

  • How can I give a specific row or cell focus (aka make them selected) programmatically?  I am trying to implement a search function.

     

    Thanks in advance.

    Friday, April 4, 2008 9:09 PM

Answers

  • try it

     

    //focus cell at position 0,0

    yourDataGridView.CurrentCell=yourDataGridView[0,0];

     

    //select cell at position 0,0

    yourDataGridView[0,0].Selected=true;

     

    Friday, April 4, 2008 9:22 PM
  •  That Asian Guy wrote:

    How can I give a specific row or cell focus (aka make them selected) programmatically?  I am trying to implement a search function.

     

    Thanks in advance.

    Code Snippet

     

    for (int jj = 0; jj < this.dataGridView1.Rows.Count; jj++)

    {

    this.dataGridView1.Rows[ jj ].Cells[ 0 ].Selected = true;

    break;

    // alternatively:

    this.dataGridView1.Rows[ jj ].Selected = true;

    break;

     

    }

     

     

     

    Friday, April 4, 2008 9:25 PM

All replies

  • try it

     

    //focus cell at position 0,0

    yourDataGridView.CurrentCell=yourDataGridView[0,0];

     

    //select cell at position 0,0

    yourDataGridView[0,0].Selected=true;

     

    Friday, April 4, 2008 9:22 PM
  •  That Asian Guy wrote:

    How can I give a specific row or cell focus (aka make them selected) programmatically?  I am trying to implement a search function.

     

    Thanks in advance.

    Code Snippet

     

    for (int jj = 0; jj < this.dataGridView1.Rows.Count; jj++)

    {

    this.dataGridView1.Rows[ jj ].Cells[ 0 ].Selected = true;

    break;

    // alternatively:

    this.dataGridView1.Rows[ jj ].Selected = true;

    break;

     

    }

     

     

     

    Friday, April 4, 2008 9:25 PM
  • Thank you! Stick out tongue

     

    Friday, April 4, 2008 10:08 PM
  •  That Asian Guy wrote:
    Thank you!

     

    Sunday, April 6, 2008 7:27 AM