AD
Administrator
Syncfusion Team
February 10, 2003 06:53 PM UTC
Following code should work:
[C#]
bool fillLastColumn = false;
protected virtual void GridQueryColWidth(object sender, GridRowColSizeEventArgs e)
{
if (this.fillLastColumn && e.Index == Grid.ColCount)
{
int width = Grid.ColCount <= 0 ? 0 : Grid.ColWidths.GetTotal(0, Grid.ColCount-1);
e.Size = Grid.ClientRectangle.Width-width;
e.Handled = true;
}
}
[VB]
Dim fillLastColumn As Boolean = False
Protected Overridable Sub GridQueryColWidth(sender As Object, e As GridRowColSizeEventArgs)
If Me.fillLastColumn AndAlso e.Index = Grid.ColCount Then
Dim width As Integer = IIf(Grid.ColCount <= 0, 0, Grid.ColWidths.GetTotal(0, Grid.ColCount - 1))
e.Size = Grid.ClientRectangle.Width - width
e.Handled = True
End If
End Sub 'GridQueryColWidth
Stefan
IP
Ivan Pelly
February 24, 2003 01:54 PM UTC
How would one implement the same concept in the GridDataBoundGrid? Thanks!
AD
Administrator
Syncfusion Team
February 24, 2003 03:38 PM UTC
You add a handler to the GridDataBoundGrid.Model.QueryColWidths event (instead of the GridControl.QueryColWidths event).
Also, you may have to set GridDataBoundGrid.AllowResizeToFit = False
IP
Ivan Pelly
February 25, 2003 07:05 PM UTC
This sort of works if the column is initially visible in the grid, however, if you resize the form, making it larger, the grid takes on a "smeared" appearance, as in the illustration attached.
If the column is not initially visible in the grid, but happens to be off to the right, wherein you need to scroll to the right to see it, the code doesn't seem to have an effect.
Do you think there's a better way to "glue" the righthand edge of the rightmost column to the lefthand edge of the vertical scrollbar? Thanks!
AD
Administrator
Syncfusion Team
February 25, 2003 09:06 PM UTC
To handle the first painting problem, you can add a handler for SizedChanged and refresh the grid there.
To handle the second problem, you have to adjust how the widths are sum when the remianing size is computed.
Attached is a sample that tries to do this.
IP
Ivan Pelly
February 26, 2003 01:19 PM UTC
Thanks! That seems to work, unless there are frozen columns. Do you think it's a quick fix to work when some columns are frozen? Thanks again!
AD
Administrator
Syncfusion Team
February 26, 2003 02:21 PM UTC
Probably. Instead of using column 0 in QueryColWidths, use the frozencol count.
IP
Ivan Pelly
February 26, 2003 04:18 PM UTC
I got that to work, but I notice in two different grids I get two different behaviors... in the GridQueryColWidth method for one of the grids, the values of e.Index range from 0 to the number of visible columns + 1 (some columns are hidden). In another grid, e.Index ranges from 0 to the number of Visible columns. The problem is that, in order to determine whether I'm handling the rightmost column, I compare e.Index to the number of visible columns - which works when e.Index and the number of visible columns coincide. What range of values should I expect for e.Index? Thanks
AD
Administrator
Syncfusion Team
February 26, 2003 04:57 PM UTC
e.Index can go up to the number of columns in the grid.
IP
Ivan Pelly
February 26, 2003 06:08 PM UTC
So what's a foolproof way to catch e.index when it is refers to the rightmost visible column in the grid?
IP
Ivan Pelly
February 26, 2003 06:13 PM UTC
So what's a foolproof way to catch e.index when it is refers to the rightmost visible column in the grid?
AD
Administrator
Syncfusion Team
February 26, 2003 06:40 PM UTC
I'd say you would have to take the column count, and the number of hidden columns on the right, and subtract the two values. To count the hidden columns on the right, loop down from ColCount, counting the number of hidden columns. You can test whether a column is hidden testing Model.Cols.Hidden(col).
AL
Alla
October 7, 2003 01:13 PM UTC
Hi,
I'm trying to solve the same problem, but I don't want to change the size of right most column. I'm talking about DataBoundGrid, and I want the right column to fit it's data. I want to add the "white area" to left column. Is there any way to do it? May be I can precomute "white area" before QueryColWidth is called for left column?
Thanks.
AD
Administrator
Syncfusion Team
October 7, 2003 03:15 PM UTC
Instead of
if (... e.Index == Grid.ColCount)
you could replace Grid.ColCount with the specific column that you want to enlarge.
Stefan
AL
Alla
October 8, 2003 08:26 AM UTC
Hi Stefan,
I am sorry for badly stated question, I'll try again.
I am trying to implement RightToLeft grid,
means that right column in grid must visually be the first column, thats why I don't want to see white area after the right column while scrolling to the right. I also don't want to enlarge any column (the column width must fit it's data), what I want to do is stop scrolling when right edge of right column is reached (or smth like that).
Thank you.
AD
Administrator
Syncfusion Team
October 8, 2003 11:38 AM UTC
Alla,
I don't think you can implement RightToLeft behavior by handling QueryColWidth event. There needs to be some code changes in the source code in order to have correct scrolling behavior. We get asked for RTL quite a lot recently and our plan is to work on this sometime after version 2.0. So, if your timeframe does allow you to wait a couple of months that would be the best.
Stefan
AL
Alla
October 8, 2003 01:35 PM UTC
Hi Stefan,
I know that you are planning to work on it, but I have only several days, I tried to do something patch style. If you say that there is no way to do so.... :(
Thank you for reply.
AD
Administrator
Syncfusion Team
October 8, 2003 02:43 PM UTC
The only trick I can imagine would be to show two grids. The right grid just shows row headers. The left grid the columns. Both grids have there horizontal scrollbars completely disabled. Instead of using the grids scrollbars you put the left grid inside a Panel. And you initialize the panels DisplaySize to the total width of all columns. Then the panel would should scrollbars and you could scrol pixel wise the left grid while the right grid stays frozen.
See also the following sample for embedding the grid inside a panel:
Stefan
BH
Bernard Herrok
December 22, 2004 07:35 PM UTC
I can''t seem to find the Grid1.GridControl.QueryColWidth.
I''ve tried Grid1.TableControl.QueryColWidth, but nothing.
Which method do i add the handler to?
I''m using a grouping grid.
AD
Administrator
Syncfusion Team
December 23, 2004 11:53 PM UTC
Try this.
Subscribe to these events.
this.gridGroupingControl1.TableModel.QueryColWidth += new GridRowColSizeEventHandler(TableModel_QueryColWidth);
this.gridGroupingControl1.TableControl.SizeChanged += new EventHandler(TableControl_SizeChanged);
with these handlers:
private void TableModel_QueryColWidth(object sender, GridRowColSizeEventArgs e)
{
int row, col;
if(this.gridGroupingControl1.TableDescriptor.ColumnToRowColIndex("Col3", out row, out col)
&& e.Index == col)
{
e.Size = this.gridGroupingControl1.TableControl.ClientSize.Width - this.gridGroupingControl1.TableModel.ColWidths.GetTotal(0, e.Index - 1) ;
e.Handled = true;
}
}
private void TableControl_SizeChanged(object sender, EventArgs e)
{
this.gridGroupingControl1.TableControl.Refresh();
}
PB
Philip Bishop
March 12, 2008 03:20 PM UTC
I have a question about the following code you gave in this article...here is the code..
Dim fillLastColumn As Boolean = False
Protected Overridable Sub GridQueryColWidth(sender As Object, e As GridRowColSizeEventArgs)
If Me.fillLastColumn AndAlso e.Index = Grid.ColCount Then
Dim width As Integer = IIf(Grid.ColCount <= 0, 0, Grid.ColWidths.GetTotal(0, Grid.ColCount - 1))
e.Size = Grid.ClientRectangle.Width - width
e.Handled = True
End If
End Sub 'GridQueryColWidth
Can I use this code but instead of resizing the last col to fill up the empty space, can I use it to make the second to the last col fill up the empty space. We have a grid that has the last col hidden. So I would like the second to the last col to fill up the extra space. Also in the example, where does the fillLastColumn bln variable ever get set to anything other then false when you dimmed it. I couldn't seem to figure that out.
PB
Phil Bishop
March 14, 2008 02:09 PM UTC
Any ideas on this?
AN
Anonymous
March 14, 2008 03:34 PM UTC
You will have to adjust the code to size the grid.ColCount-1 column instead of the grid.ColCount column. Attached is a little sample showing something like this.
WindowsApplication4.zip