We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Extend most right column

Thread ID:

Created:

Updated:

Platform:

Replies:

2699 Feb 10,2003 07:33 AM Mar 14,2008 11:34 AM Windows Forms 23
loading
Tags: GridControl
Barbara Arz
Asked On February 10, 2003 07:33 AM

How is it possible to extend the right most column, so that the grid is filled without showing a scrollbar? Thanxs for help in advance. Barbara

Administrator [Syncfusion]
Replied On February 10, 2003 01:53 PM

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

Ivan Pelly
Replied On February 24, 2003 08:54 AM

How would one implement the same concept in the GridDataBoundGrid? Thanks!

Administrator [Syncfusion]
Replied On February 24, 2003 10:38 AM

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

Ivan Pelly
Replied On February 25, 2003 02:05 PM

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!

Administrator [Syncfusion]
Replied On February 25, 2003 04:06 PM

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.

Ivan Pelly
Replied On February 26, 2003 08:19 AM

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!

Administrator [Syncfusion]
Replied On February 26, 2003 09:21 AM

Probably. Instead of using column 0 in QueryColWidths, use the frozencol count.

Ivan Pelly
Replied On February 26, 2003 11:18 AM

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

Administrator [Syncfusion]
Replied On February 26, 2003 11:57 AM

e.Index can go up to the number of columns in the grid.

Ivan Pelly
Replied On February 26, 2003 01:08 PM

So what's a foolproof way to catch e.index when it is refers to the rightmost visible column in the grid?

Ivan Pelly
Replied On February 26, 2003 01:13 PM

So what's a foolproof way to catch e.index when it is refers to the rightmost visible column in the grid?

Administrator [Syncfusion]
Replied On February 26, 2003 01:40 PM

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).

Alla
Replied On October 7, 2003 09:13 AM

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.

Administrator [Syncfusion]
Replied On October 7, 2003 11:15 AM

Instead of if (... e.Index == Grid.ColCount) you could replace Grid.ColCount with the specific column that you want to enlarge. Stefan

Alla
Replied On October 8, 2003 04:26 AM

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.

Administrator [Syncfusion]
Replied On October 8, 2003 07:38 AM

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

Alla
Replied On October 8, 2003 09:35 AM

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.

Administrator [Syncfusion]
Replied On October 8, 2003 10:43 AM

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

Bernard Herrok
Replied On December 22, 2004 02:35 PM

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.

Administrator [Syncfusion]
Replied On December 23, 2004 06:53 PM

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(); }

Philip Bishop
Replied On March 12, 2008 11:20 AM

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.



Phil Bishop
Replied On March 14, 2008 10:09 AM

Any ideas on this?


Anonymous
Replied On March 14, 2008 11:34 AM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;