DataGridView making a row visible

C

colin

Hi,
I need to tell how many rows are visible on the screen,
in my DataGridView control
so that I can ensure my newly selected row is visible
without doing any unecessry scrolling,

I thought RowCount would give me this :-
Summary:
Gets or sets the number of rows displayed in the
System.Windows.Forms.DataGridView.

but this isnt meaning the number dispalyed on the screen,
im not sure what it is, it serems to be the same as the number of rows in
the coollection.
I gues it just truncates the number of rows.

it conveniently tells you the first visible row
but not the last it seems, unless I am missing something.

is there another way to get this info ?
or do i have to work it out using pixels :s

Colin =^.^=
 
G

Greg

Hi,
 I need to tell how many rows are visible on the screen,
in my DataGridView control
so that I can ensure my newly selected row is visible
without doing any unecessry scrolling,

I thought RowCount would give me this :-
Summary:
Gets or sets the number of rows displayed in the
System.Windows.Forms.DataGridView.

but this isnt meaning the number dispalyed on the screen,
im not sure what it is, it serems to be the same as the number of rows in
the coollection.
I gues it just truncates the number of rows.

it conveniently tells you the first visible row
but not the last it seems, unless I am missing something.

is there another way to get this info ?
or do i have to work it out using pixels :s

Colin =^.^=

I thought RowCount would have worked too.
However, if you want to show your newly 'selected' row,
then simply use DataGridView.FirstDisplayedScrollingRowIndex =
rowIndex.

Greg
 
C

colin

Greg said:
Hi,
.>I need to tell how many rows are visible on the screen,
I thought RowCount would have worked too.
However, if you want to show your newly 'selected' row,
then simply use DataGridView.FirstDisplayedScrollingRowIndex =
rowIndex.

Greg

ah yes I do that already, I realy thought id mentioned that.. oh well,
anyway that scrolls the selection to be at the top of the list always,
but the selection is set via a mousehover on a 3d graphical object,
wich are wireframe models,
when the mouse is moving accros several objects
its scrolling up and down like crazy and its a bit of a pain.

I had hoped to only scroll up or down as few lines as possible to bring it
into view,
for now im just assuming theres 8 lines.

for(int i=0;i < grid.Rows.Count;i++)
{
if(grid.Rows.Tag == selection)
{
if (!grid.Rows.Selected)
{
grid.ClearSelection();
grid.Rows.Selected = true;
if (i < grid.FirstDisplayedScrollingRowIndex)
grid.FirstDisplayedScrollingRowIndex = i;
else if (i >= grid.FirstDisplayedScrollingRowIndex + 8)
grid.FirstDisplayedScrollingRowIndex = i - (8-1);

Colin =^.^=
 

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

Top