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

How to set column width in GridListControl?

I have GridListControl whose DataSource is being set to a collection. After doing this, the columns appear to resize themselves to be able to display all data, but I can''t seem to resize the columns the way I want them to look. I found someone else asking a similar question in this thread: http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=29020 . However, the code example posted doesn''t work with Option Strict On. This line gives an error: Dim cr As GridDropDownGridListControlCellRenderer = cc.Renderer I tried to get around this with a CType(), but the object "cr" always appears to end up as Nothing. Am I missing something here?

4 Replies

AD Administrator Syncfusion Team May 25, 2005 03:40 PM

The other code should be used only when a grid is using a GridListControl as a CellType, and only when the currentcell is one of these GridListControl CellTypes. Another way to get the renderer from a grid celltype is to use code like: Dim cr as GridDropDownGridListControlCellRenderer = CType(me.Grid.CellRenderers("GridListControl"), GridDropDownGridListControlCellRenderer) But if you just have a GridListControl1 stand-alone on a form, then you can use like this to set the colwidths. Me.gridListControl1.Grid.ColWidths(1) = 150


AD Administrator Syncfusion Team May 25, 2005 04:20 PM

Okay, I tried the new "Dim cr..." line of code you recomended, and cr was successfully set to something. However, the QueryColWidth never appears to fire. This is, roughly, how my code looks (edited for simplicity). The owner of an instance of this class is meant to call the Populate method separately (it''s a little more complicated in my actual app), but I think that should affect anything. I''ve included it here just in case. Public Class SyncFusionGridCombobox Inherits Syncfusion.Windows.Forms.Tools.ComboBoxExt '' The grid that will be displayed in the dropdown list Public DropDownGrid As New GridListControl Protected cc As GridCurrentCell Protected cr As GridDropDownGridListControlCellRenderer Protected glc As GridListControl Public Sub New() cc = DropDownGrid.Grid.CurrentCell cr = CType(DropDownGrid.Grid.CellRenderers("GridListControl"), _ GridDropDownGridListControlCellRenderer) AddHandler cr.ListControlPart.Grid.QueryColWidth, _ AddressOf QueryColWidthHandler Me.ListControl = DropDownGrid Me.PopupControl = DropDownGrid End Sub Protected Sub QueryColWidthHandler(ByVal sender As Object, _ ByVal e As GridRowColSizeEventArgs) Console.WriteLine("QueryColWidth") End Sub Public Sub Populate() Dim myColl As CustomCollection '' Get a collection myColl = New CustomCollection '' Bind procedure collection to the grid DropDownGrid.DataSource = myColl DropDownGrid.DisplayMember = "Something" DropDownGrid.ValueMember = "SomethingElse" End Sub End Class The "cc =...","cr =...", and "AddHandler..." lines of code in the constructor seem to work fine, but it doesn''t look like QueryColWidth ever fires, since nothing is ever outputted to the Console window.


AD Administrator Syncfusion Team May 25, 2005 06:51 PM

You are not using a GridDropDownGridListControlCellRenderer. This object is used in a GridControl or GridDataBoundGrid when you set a style.CellType = "GridListControl". You have a GridListControl being used as a dropdown in a ComboBoxExt. This is not using a GridDropDownGridListControlCellRenderer. In your case, you can just explicitly set the widths if you want to. But if you want to subscribe to the QueryColWidth event to manage this too. Here is a sample that shows how to do either. First, just drop the combobox and note the colwidths. Then click each button and then drop the combo again to see the effect. http://www.syncfusion.com/Support/user/uploads/GLC_In_Combobox_1323901a.zip


AD Administrator Syncfusion Team May 26, 2005 08:35 AM

I swear, setting the ColWidths property was the first thing I tried, but it didn''t work. Now it does. Go figure.

Loader.
Live Chat Icon For mobile
Up arrow icon