Custom Windows DataGrid

B

Bob The Builder

I have a custom-built datagrid for windows forms. I overrode the
scrollbars in it because I wanted to draw my own (basically, they're
skinned). As a result, I handle all scroll events and calls. I also
have a row-selector column as the first column, and that needs to stay
visible. Think Excel. However, if a user clicks a cell that is all
the way to the right and goes off the grid a bit, then the entire grid
shifts, including my row-selector column. I can't find any event that
seems to coincide with this. Yes, CurrentCellChanged fires, but by
then it's too late to prevent the grid from scrolling.
So, does anyone know a good way to make a column freeze (this is a
windows forms application), and how can I prevent the grid from auto
scrolling? Thanks
 
B

Bob The Builder

Perhaps, but this is for a large-scale commercial application that's
been in development for over 2 years. We're releasing 2.5 soon and
really don't have time/resources to convert to 2005. Believe me, I've
been reading all the great stuff that's in VB2005 and SQL 2005, but
until then, I have to re-create these features in 2003. Thanks
anyway...
 
G

Guest

Bob,
I know how cool custom scrolls can be. This is just me I would make all the
columns fit exactly on the visible display area of the data grid by adjusting
the column width. Too many columns then hide the columns that don't fit.
You'll have to use the tablestyles collection
Its dificult to setup but here goes
click properties
set the width to 420
select tablestyles collection and go to the designer ...
add a tablestyle just click the big add button
in the mapping name select your datamember (datamember on grid) name from
the drop down list
go into the grid columns styles collection designer ... (same designer)
in the mapping name select your first column from the drop down list.
set width to 100
do the same for the next three columns
for all the remaining columns set the width to zero.
when you run the datagrid will display the first four columns.
In the cool scroll click to move right. make columns visible by changing
the width to non zero.

datagrid1.TableStyles.Item(0).GridColumnStyles.Item(0).Width=0
datagrid1.TableStyles.Item(0).GridColumnStyles.Item(4).Width=100

Sorry I don't know how to progamatically create a table styles collection at
run time you'll have to do it manually in the designer.

Good Luck
DWS
 
B

Bob The Builder

That's essentially what I'm doing now, except it's programmatically. I
have a class that inherits from DataGridTextBoxColumn (for custom
coloring and properties). I iterate through the columns in my
DataSource, and call BaseStyle.GridColumnStyles.Add(gridCol), where
gridCol is my DataGridTextBoxColumn.
But, scrolling with the scrollbar really isn't the issue. The problem
is when a user clicks on a cell that hangs off the edge of the grid.
That is, a cell whose .Left property is within the grid, but .Left +
..Width is beyond the width of the grid. And the columns must have
variable width.
 

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