Scrolling problems in datagrid with invisible columns

  • Thread starter Igor Mendizabal
  • Start date
I

Igor Mendizabal

Hello,

We're doing our own datagrid based on the System.windows.forms.datagrid
control, and are having some problems with horizontal scrolling.

In general, we construct our datagrid adding a tablestyle and
gridcolumnstyles to that tablestyle. If we have invisible columns, we add
the gridcolumnstyle with Width = 0 (couldn't find any other way to do it,
because there is no Visible property available...).

When we change column with the TAB key, it doesn't work right if the
invisible columns are in the visible area of the grid. Looking at the code
of the EnsureVisible method of the datagrid, it's something like this:
-----------------------------------------------------------
private void EnsureVisible(int row, int col) {
int local0;
if (row < this.firstVisibleRow || row >= this.firstVisibleRow +
this.numTotallyVisibleRows) {
local0 = this.ComputeDeltaRows(row);
this.ScrollDown(local0);
}
if (this.firstVisibleCol != 0 || this.numVisibleCols != 0 ||
this.lastTotallyVisibleCol != -1)
goto i-1;
return;
do {
this.ScrollToColumn(col);
} while (col < this.firstVisibleCol || col == this.firstVisibleCol &&
this.negOffset != 0 || this.lastTotallyVisibleCol == -1 && col >
this.firstVisibleCol || this.lastTotallyVisibleCol > -1 && col >
this.lastTotallyVisibleCol);
}
-----------------------------------------------------------
The problem is that, even if we can't see, for example, the column 0 because
it has its Width=0, the datagrid keeps saying that FirtsVisibleCol=0, so it
doesn't scroll right when it should. I guess the same is happening with the
rest of the private properties (numVisibleCols and lastTotallyVisibleCol)

Anybody has any ideas of how we can solve this problem? Is there a way to
tell the datagrid that Column0 is actually invisible?

Right now, the only way I can think of doing it is controlling columns with
Width=0 and scrolling the grid "by hand"...

Thank You very much,

Igor Mendizabal
 
I

Igor Mendizabal

Hello Cor,

I thought about your suggestion, but doesn't work in our case. The problem
is that our grids are mostly configurable by the user (they can
enable/reorder/hide columns), and there is a lot of code written by now that
accesses those columns, even if they are hidden, because it supposes that
they are there, only that we can't see them.

Anyway, I tried not to add the invisible gridcolumnstyles, and even thogh
the scrolling works fine, I broke more things than I fixed with that change,
so I'm gonna try to control if it should scroll in the CurrentCellChanged
event, and use the GridHScrolled method to make it scroll.

Thank you very much anyway,

Igor
 
C

Cor Ligthert [MVP]

Igor,

AFAIK is setting the mapping of a column to nothing enough to do what you
want when you use tablestyles.

Cor
 

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