By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,369 Members | 1,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,369 IT Pros & Developers. It's quick & easy.

DataGridView question

P: n/a
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
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
--
Dipl.Inf. Frank Dzaebel [MCP/MVP C#]
http://Dzaebel.NET

Nov 17 '05 #2

P: n/a
"Frank Dzaebel" <Po**@FranksSeite.de> wrote in
news:OT**************@TK2MSFTNGP09.phx.gbl:
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
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.