|
hy,
The following layout problem. I have a table with a variable number of rows and columns. Each row represents a student. The first column of this table contains the student name, this colomn should be always vissible, the width of this column adjustable with a splitter. If the width is less then the width of the name labels inside this column, a horizontal scroll bar should appear underneath this first column. The other collumns represent workingdays. the number of days is variable. these columns have a fixed width of 20px. if the total width of these columns exeed the width of the parent panel a scroll bar should appear under these columns. If the height of the rows exeeds the height of the panel a vertical scroll bar should appear to scroll the whole tabel up down. (i.e. I could have two horizontal scroll bars and one vertical)
I thought to put a splitterpanel on my form and drop 2 tablelayoutpanels, one on each side of the splitter . put the autoscroll of both tablelayoutpanels to true, 1 column in the left table and a dynamicly variable number of columns in the right table, and ready! But no, it works for the splitter and the horizontal scroll bars, but I get two vertical scrollbars witch are very hard to synchronise. and when only one panel Auto shows its scrollbars, the other one is not adjustable at all. I thougt to use the vertical scroll bar of the underlaying righthand splitpanel but then the horizontal sroll is not right.
Questions: 1: Is it somehow possible to use only the horizontal or the vertical (auto?) scroll function of a tableLayout pannel or a splitter panel?
2: What would be the best design solution for this problem? Should I use a datagrid? but how to keep the left most column in view then and how to put a scroll bar just under this column if nessesair and an other scrollbar under the other columns??
Thanks for your help, I am puzzeling for days now.
Regards
Rob
| | rob warning Monday, October 05, 2009 10:17 AM | Hi,
I think a DataGridView control would be a better choice. I think it supports the notion of 'frozen' columns, these are columns (on the left most side of the grid) which are 'frozen' and therefore don't scroll when the horizontal scrollbar is moved. The DataGridView also supports resizing columns, similar to the way a splitter works so that would allow you to resize that column based on the contents.
I'm not sure there is a good way to put a horizontal scrollbar under an individual column. The only thing I can think to do is to put a single horizontal scrollbar under the column of the data grid view and manually write code to handle it's scroll event. I'm not sure what that code would look like, it may require an owner drawn column. You'd also have to write code to resize the scrollbar when the column its visually associated with changes width.
Using a data grid is not only more likely to work, but it will use less memory (fewer window handles etc) and will likely have fewer redraw issues.
Table layouts are great, but they don't work well when dynamically creating controls and I don't think they support the kind of scrolling functionality you want.
| | Yort Tuesday, October 06, 2009 2:07 AM | Thank you Yort,
I will certainly try your suggestion about using a datagrid. I did not know that it is possible to freeze the left most column. But what I actualy would like to do is to use the VScroll and Hscroll properties of the TableLayoutpanels to individualy set the visibility (and I hope functionality) of the scrollbars. The tablelayoutpanel is derived from a ScrollableControl so these properties are inside, but I think they are local to the TableLayoutControl it self. Using the tableLayoutPanel1.HorizontalScroll.Visible property in combination with the autoscroll=false makes the scrollbar visible but only if the columns are autosize. and beside this they do not function as expected.
I also try to use a individual Vscrollbar and and 2 Hscrollbars on the splitcontainer. visualy thats exactly what I would like. But I am puzzeling how to make these scroll bars functional on the tableLayoutPanels. The whole scrolling logic seems to be hidden inside the TableLayoutPanel component.
One problem with a datagrid would be that I like to use a custom user control in the Individual cells of the second layoutpanel. I dont know if that is possible with a datagrid?
A lot of questions as you see. If nothing works like I want ,I should maybe try to make a custom user grid my self. But I would have to do quite some study to accomplish this ;-)
regards
Rob | | rob warning Tuesday, October 06, 2009 11:04 AM | Hi,
No problem.
I don't know how to do what you want with the TLP control, as you say, the scrolling logic is built inside of the control to do what most people want and here that doesn't suit you. You *might* be able to build your own TLP by inheriting from the existing one, and then you've be able to call and override protected members as well as the normal public ones, but that still may not help you.
While there is a little bit of work involved, it is possible to put a user control inside a data grid cell. To do this you have to build not only your user control but also your own DataGridViewColumn and DataGridViewCell objects that work with that control, then add your custom column type to the grid. There are plenty of samples on the internet, and in the MSDN documentation I think, for this. Google should help you with that. It's been over 5 years since I last did that, so I may not be able to help much (my memory isn't great) but if you have a specific problem with that process post in the forums again, I'm sure someone can help.
| | Yort Tuesday, October 06, 2009 8:22 PM |
|