AD
Administrator
Syncfusion Team
June 8, 2006 05:01 AM UTC
Hi JT,
In the Grid ComboBox celltype, comboBox is not directly implemented. ListBox is used for the dropdown and button is derived from GridCellButton (GridCellComboBoxButton.cs). To get the desired behavior, please add the code below in the CurrentCellShowingDropDown Event. Here is a code snippet.
private void gridControl1_CurrentCellShowingDropDown(object sender, Syncfusion.Windows.Forms.Grid.GridCurrentCellShowingDropDownEventArgs e)
{
GridCurrentCell cc = this.gridControl1.CurrentCell;
GridComboBoxCellRenderer cr = cc.Renderer as GridComboBoxCellRenderer;
if( cr != null)
{
cr.ListBoxPart.SelectedIndexChanged +=new EventHandler(ListBoxPart_SelectedIndexChanged);
}
}
private void ListBoxPart_SelectedIndexChanged(object sender, EventArgs e)
{
ListBox list = sender as ListBox;
if( list != null)
{
if( list.SelectedIndex % 2 ==0 ) //you need to check the condition for skipping the selected index.
{
if(list.Items.Count -1 == list.SelectedIndex)
{
list.SelectedIndex = 1;
}
else
list.SelectedIndex++;
}
}
}
Here is a sample.
http://www.syncfusion.com/Support/user/uploads/GridComboChoiceList_1ee3cf71.zip
Let me know if this helps.
Best Regards,
Haneef
AD
Administrator
Syncfusion Team
June 8, 2006 01:52 PM UTC
Thanks for the sample. It seems to be just what I want. I eventually want to change the color of those non clickable ones also but this is a start. Any chance I could get this in VB code?
AD
Administrator
Syncfusion Team
June 9, 2006 04:19 AM UTC
Hi JT,
To draw the nonselected Item background in a grid combobox cell, you need to set the drawing mode property of the listbox to DrawMode.OwnerDrawVariable, and draw the Items of the Listbox using the DrawItem event . Here is a code snippet.
//set the Draw mode.
cr.ListBoxPart.DrawMode = DrawMode.OwnerDrawVariable
Private SavedIndex As Integer = -1
Private Sub ListBoxPart_DrawItem(ByVal sender As Object, ByVal e As DrawItemEventArgs)
Dim list As ListBox = CType(IIf(TypeOf sender Is ListBox, sender, Nothing), ListBox)
Dim format As StringFormat = New StringFormat()
format.LineAlignment = StringAlignment.Center
format.Alignment = StringAlignment.Center
Dim rect As RectangleF = New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)
If e.Index Mod 2 = 0 Then
e.Graphics.FillRectangle(Brushes.Pink, e.Bounds)
e.Graphics.DrawString(list.Items(e.Index).ToString(), list.Font, New SolidBrush(list.ForeColor), rect, format)
Else
If list.SelectedIndex = e.Index Then
If SavedIndex <> -1 AndAlso SavedIndex <> list.SelectedIndex Then
list.Invalidate(list.GetItemRectangle(SavedIndex))
End If
SavedIndex = list.SelectedIndex
e.Graphics.FillRectangle(Brushes.Silver, e.Bounds)
e.Graphics.DrawString(list.Items(e.Index).ToString(), list.Font, New SolidBrush(list.ForeColor), rect, format)
Else
e.Graphics.DrawString(list.Items(e.Index).ToString(), list.Font, New SolidBrush(list.ForeColor), rect, format)
End If
End If
End Sub
Here is a sample.
http://www.syncfusion.com/Support/user/uploads/VBGRIDcomboChoiceList_103dc074.zip
Please let me know if this helps.
Best Regards,
Haneef