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

Grid ComboBox Height

How can I the height, or default # of items to show, in a grid cell dropdown? Thanks,

3 Replies

AD Administrator Syncfusion Team July 23, 2003 09:44 PM UTC

There is a DropDownRows property that you can set. But since the list can vary from cell to cell, you have to dynamically set this property cell to cell as well.
//C#
private void gridControl1_CurrentCellShowingDropDown(object sender, GridCurrentCellShowingDropDownEventArgs e)
{
	GridControlBase grid = sender as GridControlBase;
	if(grid != null)
	{
		GridCurrentCell cc = grid.CurrentCell;
		GridComboBoxCellRenderer cr = cc.Renderer as GridComboBoxCellRenderer;
		if(cc != null)
		{
			if(cc.RowIndex == 6)
			    ((GridComboBoxListBoxPart)cr.ListBoxPart).DropDownRows = 4;
			else if(cc.RowIndex == 4)
				((GridComboBoxListBoxPart)cr.ListBoxPart).DropDownRows = 7;
			else if(cc.RowIndex == 2)
				((GridComboBoxListBoxPart)cr.ListBoxPart).DropDownRows = 10;
			else
				((GridComboBoxListBoxPart)cr.ListBoxPart).DropDownRows = 6;
		}
	}
}

'VB.NET
    Private Sub GridControl1_CurrentCellShowingDropDown(ByVal sender As Object,   _
                 ByVal e As Syncfusion.Windows.Forms.Grid.GridCurrentCellShowingDropDownEventArgs)  _
                 Handles GridControl1.CurrentCellShowingDropDown
        Try
            Dim grid As GridControlBase = sender
            Dim cc As GridCurrentCell = grid.CurrentCell
            Dim cr As GridComboBoxCellRenderer = cc.Renderer '
            If cc.RowIndex = 6 Then
                CType(cr.ListBoxPart, GridComboBoxListBoxPart).DropDownRows = 4
            ElseIf cc.RowIndex = 4 Then
                CType(cr.ListBoxPart, GridComboBoxListBoxPart).DropDownRows = 7
            ElseIf cc.RowIndex = 2 Then
                CType(cr.ListBoxPart, GridComboBoxListBoxPart).DropDownRows = 10
            Else
                CType(cr.ListBoxPart, GridComboBoxListBoxPart).DropDownRows = 6
            End If
        Catch
        End Try
    End Sub


GW Greg Wright July 28, 2003 01:12 PM UTC

I implemented what you suggested, and initially had problems in getting it to work. It wouldn't change the height of the list at all. I had one cell dropdown with one item in it, and the dropdown list wouldn't even show that one item. After working with it for a while, I discovered that certain fonts cause problems with the dropdown heights. I was using Arial for the grid font. Once I changed it to Tahoma, if worked fine. Would this be a bug?


AD Administrator Syncfusion Team July 28, 2003 03:40 PM UTC

This does seem to be a problem. We are doing an integer calculation to get the number of pixels per row. The truncated don't seem to affect the tohoma font (losing about .12 pixels per row), but does seem to affect the tohoma font (losing about .38 pixels per row). We will have to tweak this calcualtion to avoid this roundoff problem. In the meantime, if you want to use arial, you can just fudge th1 number of rows by 1 Say you really want to see 1 row, request 2 rows...)

Loader.
Live Chat Icon For mobile
Up arrow icon