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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

DropDown ComboBox with restricted selection?

Thread ID:





44955 Jun 7,2006 06:39 PM UTC Jun 9,2006 04:19 AM UTC WinForms 3
Tags: GridControl
Administrator [Syncfusion]
Asked On June 7, 2006 06:39 PM UTC

I have a grid control with a column of dropdown combo boxes. I am loading these boxes by assigning a choice list to each combo box. Depending on certain criteria I want to be able to show all entries in the list but some I do not want the user to be able to select. Is there any way to do this?

Administrator [Syncfusion]
Replied On 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

Administrator [Syncfusion]
Replied On 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?

Administrator [Syncfusion]
Replied On 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


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.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon 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.Close Icon