DataGridView question

  • Thread starter Thread starter vbMark
  • Start date Start date
V

vbMark

Hello,

Using 2005 beta.

I can pragmatically select a cell in the DataGridView but it does not move
the cell so that it is visible on screen.

How do I make it so that the cell that I select is moved to where the user
can see that it is selected?

Thanks!

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Best free software
http://www.vbmark.com
Freeware-dedicated search engine
http://www.eurekster.com/parties/Freeware1.htm
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 
Hi,
Using 2005 beta.
I can pragmatically select a cell in the DataGridView but it does not move
the cell so that it is visible on screen.
How do I make it so that the cell that I select is moved to where the user
can see that it is selected?

private void button1_Click(object sender, EventArgs e)
{ SelectEnsureVisible(2, 20);
}

private void SelectEnsureVisible(int row, int col)
{
foreach(DataGridViewCell c in dataGridView1.SelectedCells) c.Selected =
false;
DataGridViewCell selCell = dataGridView1[row, col];
dataGridView1.FirstDisplayedCell = selCell; selCell.Selected=true;
}


ciao Frank
 
Hi,
Using 2005 beta.
I can pragmatically select a cell in the DataGridView but it does not
move the cell so that it is visible on screen.
How do I make it so that the cell that I select is moved to where the
user can see that it is selected?

private void button1_Click(object sender, EventArgs e)
{ SelectEnsureVisible(2, 20);
}

private void SelectEnsureVisible(int row, int col)
{
foreach(DataGridViewCell c in dataGridView1.SelectedCells)
c.Selected =
false;
DataGridViewCell selCell = dataGridView1[row, col];
dataGridView1.FirstDisplayedCell = selCell; selCell.Selected=true;
}


ciao Frank

Worked great. However, for anyone using this code, you need to swap row
and col.

Thanks!

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Best free software
http://www.vbmark.com
Freeware-dedicated search engine
http://www.eurekster.com/parties/Freeware1.htm
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top