I have a need to allow the user to selectively show/hide columns and change their widths in a databound grid. To do this, I have created a dialog which enumerates all columns and displays their "hidden" and "width" values as such:
_DataGrid.Model.Cols.Hidden(i)
_DataGrid.Model.ColWidths(i)
On application of the new settings, I set the hidden and width parameters as such:
_DataGrid.Model.ColWidths(i) = nSomeInt
_DataGrid.Model.Cols.Hidden(i) = fSomeBoolean
where nSomeInt is a value > 0. However, when the changes take effect, the width of the now hidden columns, no matter the previous value, is set to zero.
To restate: The behavior I am seeing is is that the following single line:
_DataGrid.Model.Cols.Hidden(nSomeIndex) = true
results not only in the hidden value changing, but also the corresponding column width being set to 0. I can see this with the debugger.
I have added a collection of GridBoundColumns to my grid for further formatting control of each column. I have noticed that the problem above does not occur in grids without GridBoundColumns.
Scott
AD
Administrator
Syncfusion Team
July 23, 2004 09:38 AM UTC
What if you switch the order of the two lines to
_DataGrid.Model.Cols.Hidden(i) = fSomeBoolean
_DataGrid.Model.ColWidths(i) = nSomeInt
Does that let the colwidths retain the values you are setting, and still keep the columns hidden if they were set to be hidden?
SL
Scott Lundgren
July 23, 2004 09:52 AM UTC
Clay,
Thanks for the suggestion - however, I''ve tried already and tried again, and it does not solve the problem.
The behavior that I am seeing is that the second line (setting the column width) has no effect on the value of the column width. This is verified using the debugger.
Scott
>
>_DataGrid.Model.Cols.Hidden(i) = fSomeBoolean
>_DataGrid.Model.ColWidths(i) = nSomeInt
>
SL
Scott Lundgren
July 23, 2004 09:59 AM UTC
Also, I should make something clear:
When the column is made visible again:
.Model.Cols.Hidden(i) = false
the width is restored, to the correct value. My problem is that, for the purposes of custom serialization, I''d like to be able to get at the "if I was visible, what width would I be" value, short of showing the column, getting the width, and hiding it again.
>
>Clay,
>
>Thanks for the suggestion - however, I''ve tried already and tried again, and it does not solve the problem.
>
>The behavior that I am seeing is that the second line (setting the column width) has no effect on the value of the column width. This is verified using the debugger.
>
>Scott
>
>>
>>_DataGrid.Model.Cols.Hidden(i) = fSomeBoolean
>>_DataGrid.Model.ColWidths(i) = nSomeInt
>>
AD
Administrator
Syncfusion Team
July 23, 2004 11:28 AM UTC
Digging through our source shows the grid.Model.ColWidths indexer explicitly returning zero if the the column is hidden. So, this behavior is by design.
The code also shows that you should be able to get the size of a hidden column if you directly call grid.Model.ColWidths.GetSize instead of going through the indexer. Hopefully this will let you do what you need to do.
SL
Scott Lundgren
July 23, 2004 11:34 AM UTC
Thanks Clay - that is what I was looking for.
Scott
SR
Shankar Ramasubramanian
December 17, 2004 12:26 PM UTC
The Getsize return -1. I''m using 2.0.5.0. I read in one of the postings that getsize return -1 if it''s a default value. So, How to get the hidden column width
>
>I have a need to allow the user to selectively show/hide columns and change their widths in a databound grid. To do this, I have created a dialog which enumerates all columns and displays their "hidden" and "width" values as such:
>
>_DataGrid.Model.Cols.Hidden(i)
>_DataGrid.Model.ColWidths(i)
>
>On application of the new settings, I set the hidden and width parameters as such:
>
>_DataGrid.Model.ColWidths(i) = nSomeInt
>_DataGrid.Model.Cols.Hidden(i) = fSomeBoolean
>
>where nSomeInt is a value > 0. However, when the changes take effect, the width of the now hidden columns, no matter the previous value, is set to zero.
>
>To restate: The behavior I am seeing is is that the following single line:
>
> _DataGrid.Model.Cols.Hidden(nSomeIndex) = true
>
>results not only in the hidden value changing, but also the corresponding column width being set to 0. I can see this with the debugger.
>
>I have added a collection of GridBoundColumns to my grid for further formatting control of each column. I have noticed that the problem above does not occur in grids without GridBoundColumns.
>
>Scott
AD
Administrator
Syncfusion Team
December 17, 2004 12:58 PM UTC
When it is -1 then you can get the default width from Model.Cols.DefaultSize.
Stefan