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. Image for the cookie policy date

GridListControl Question

Is there a way to get the same results (see code snippet below) with the GridListControl? I want to rearrange the order in which my columns are displayed in the GridListControl. I'm binding to a custom collection class. gbc = New GridBoundColumn gbc.MappingName = "BillingStreetAddress" gbc.HeaderText = "Street Address" grdResults.GridBoundColumns.Add(gbc) Thanks in advance, Andrew

4 Replies

AD Administrator Syncfusion Team July 17, 2003 06:55 AM UTC

> Is there a way to get the same results (see code snippet below) with the GridListControl? I want to rearrange the order in which my columns are displayed in the GridListControl. I'm binding to a custom collection class. > > > gbc = New GridBoundColumn > gbc.MappingName = "BillingStreetAddress" > gbc.HeaderText = "Street Address" > grdResults.GridBoundColumns.Add(gbc) > > Thanks in advance, > > Andrew It is not as easy. The GridListControl started life as a sample, and its primary purpose was to serve as the list part of a multicolumn dropdown list for a grid cell. So, it does not have all the property structures that let you easily design it. In a lot of cases, it is simpler to use either a GridDataBoundGrid or a GridControl, jsut setting the ListBoxSelectionMode to make these controls behave like a list. You can hide teh row headers, and handle the CurrentCellActivating evet setting e.ColIndex = 0 to get more or less the exact same look. You cn also make grid.TableStyle.CellType = "Static" to avoid all editing problems. If you use one of these controls, you can set the headertext using code like you suggested above or something equivalent for a GridControl. If you really need teh GridListControl foe some reason (maybe your design required a ListBox derived class), then you can change teh headertext but it is a little more more. you have to get at the embbedded GridControl, gridListControl1.Grid. But even if you get at this control, since the GridListControl uses this embedded grid in a virtual manner, you have to handle the QueryCellInfo event, an dprovide the header text on demand.
’add the handler say in the form’s Load event
        AddHandler GridListControl1.Grid.QueryCellInfo, AddressOf HandleGridQueryCellInfo

’here is the handler that changes the title of column 1 to "NewTitle"
Private Sub HandleGridQueryCellInfo(ByVal sender As Object, ByVal e As GridQueryCellInfoEventArgs)
        If e.ColIndex = 1 And e.RowIndex = 0 Then
            e.Style.Text = "NewTitle" ' for col 1
            e.Handled = True
        End If
EndSub


AN Andrew July 17, 2003 09:56 AM UTC

Thanks for the suggestion, I'll use the GridDataBoundGrid and edit the properties you suggested. Basically, I want to accomplish the following: 1.) Load records into the control from a custom collection, but I want the columns to be displayed in a different order than how it's declared in the collection class. 2.) I want the control to have a spreadsheet look, I don't know if this is possible. What I mean is that I want the control to be filled with rows, even if there is no data in them. I think I can set the amount of rows I want displayed in the grid and then use the populate method to copy the values from my collection to the GridDataBoundGrid. Is this correct, or do I have to use the GridControl to do this? 3.) I would like the columns to adjust their width to fit the entire width of the control. Is there a way to have the columns adjust to the size of the grid control automatically, or do I have to set the width of each cell manually? 4.) I would also like to have the whole row selected when the end user clicks on any field in a row. Thanks in advance, your help is much appreciated. Andrew > > Is there a way to get the same results (see code snippet below) with the GridListControl? I want to rearrange the order in which my columns are displayed in the GridListControl. I'm binding to a custom collection class. > > > > > > gbc = New GridBoundColumn > > gbc.MappingName = "BillingStreetAddress" > > gbc.HeaderText = "Street Address" > > grdResults.GridBoundColumns.Add(gbc) > > > > Thanks in advance, > > > > Andrew > > It is not as easy. The GridListControl started life as a sample, and its primary purpose was to serve as the list part of a multicolumn dropdown list for a grid cell. So, it does not have all the property structures that let you easily design it. > > In a lot of cases, it is simpler to use either a GridDataBoundGrid or a GridControl, jsut setting the ListBoxSelectionMode to make these controls behave like a list. You can hide teh row headers, and handle the CurrentCellActivating evet setting e.ColIndex = 0 to get more or less the exact same look. You cn also make grid.TableStyle.CellType = "Static" to avoid all editing problems. > > If you use one of these controls, you can set the headertext using code like you suggested above or something equivalent for a GridControl. > > If you really need teh GridListControl foe some reason (maybe your design required a ListBox derived class), then you can change teh headertext but it is a little more more. you have to get at the embbedded GridControl, gridListControl1.Grid. But even if you get at this control, since the GridListControl uses this embedded grid in a virtual manner, you have to handle the QueryCellInfo event, an dprovide the header text on demand. > >
> ’add the handler say in the form’s Load event
>         AddHandler GridListControl1.Grid.QueryCellInfo, AddressOf HandleGridQueryCellInfo
> 
> ’here is the handler that changes the title of column 1 to "NewTitle"
> Private Sub HandleGridQueryCellInfo(ByVal sender As Object, ByVal e As GridQueryCellInfoEventArgs)
>         If e.ColIndex = 1 And e.RowIndex = 0 Then
>             e.Style.Text = "NewTitle" ' for col 1
>             e.Handled = True
>         End If
> EndSub
> 
> >


AD Administrator Syncfusion Team July 17, 2003 12:39 PM UTC

2) there is a property you can set to get this. this.gridDataBoundGrid1.Model.Options.DisplayEmptyRows = true; 3) You should handle Model.QueryColWidth and set the width to a size equal to 1/numCols times teh grid's client width. Here is a sample handler from the GridDataBoundImages sample that support this type of propertional sizing. One last comment is to set grid.SmoothControlResize = false so it draws ok as you size it through its parent.
private void GetColWidth(object sender, GridRowColSizeEventArgs e)
{
	if(this.proportionalCellSizing && e.Index > 0)
	{
		e.Size = (int) ((this.gridDataBoundGrid1.ClientRectangle.Width - this.gridDataBoundGrid1.Model.ColWidths[0]) / (float)this.gridDataBoundGrid1.Model.ColCount);
		e.Handled = true;
	}
}
4) set the grid.ListBoxSelectionMode = SelectionMode.One. Also handle, grid.CurrentCellActivating, and in your handler, set e.ColIndex = 0.


AN Andrew July 17, 2003 04:00 PM UTC

Thanks for all your help! > Is there a way to get the same results (see code snippet below) with the GridListControl? I want to rearrange the order in which my columns are displayed in the GridListControl. I'm binding to a custom collection class. > > > gbc = New GridBoundColumn > gbc.MappingName = "BillingStreetAddress" > gbc.HeaderText = "Street Address" > grdResults.GridBoundColumns.Add(gbc) > > Thanks in advance, > > Andrew

Loader.
Live Chat Icon For mobile
Up arrow icon