473,322 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Combo Box selection

This is a newbie question.

I have a combo box in where the end user will select an item (an obedience
class - yes for dogs, not for developers) and then assign an obedience judge
to that class. When they save this record, I do not want that class in the
combo box to be enabled. Is there a way to 'disable' this selection only,
while keeping the other classes available to the user. And then on the flip
side, if the user deletes that obedience event record, this item will be
re-enabled in the list.

Thanks for the information.

Brad
Nov 20 '05 #1
1 1859
On Sun, 19 Oct 2003 09:54:45 -0400, "Brad Allison"
<ku****@charter.net> wrote:
This is a newbie question.

I have a combo box in where the end user will select an item (an obedience
class - yes for dogs, not for developers) and then assign an obedience judge
to that class. When they save this record, I do not want that class in the
combo box to be enabled. Is there a way to 'disable' this selection only,
while keeping the other classes available to the user. And then on the flip
side, if the user deletes that obedience event record, this item will be
re-enabled in the list.


No. With the existing ComboBox you can only Remove items. I've knocked
up an "AdvancedComboBox" that implements a "Disabled" collection.
Adding items to this collection will make the items unselectable and
grey them out. You will want to make some changes - particularly with
the behaviour. Cursor keys up and down the list should skip disabled
items. I've also been a bit lazy about the hilighting - Background
colour should be changed, and DrawBackground() should be called under
all circumstances.

--begin AdvancedComboBox.vb--
Public Class AdvancedComboBox
Inherits Windows.Forms.ComboBox

Private mDisabledItems As New ArrayList()
Private mPreviousIndex As Integer = -1

Public Sub New()
MyBase.New()
MyBase.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
MyBase.DropDownStyle = ComboBoxStyle.DropDownList
End Sub

Public ReadOnly Property DisabledItems() As IList
Get
Return mDisabledItems
End Get
End Property

Private Sub AdvancedComboBox_DrawItem(ByVal sender As Object,
ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles
MyBase.DrawItem
If e.Index = -1 Or e.Index > MyBase.Items.Count - 1 Then
e.DrawBackground()
Exit Sub
End If

Dim oTextBrush As Brush
If e.State And DrawItemState.Selected Then
If mDisabledItems.Contains(MyBase.Items.Item(e.Index) )
Then
oTextBrush =
System.Drawing.SystemBrushes.InactiveCaption
Else
e.DrawBackground()
oTextBrush =
System.Drawing.SystemBrushes.HighlightText
End If
Else
e.DrawBackground()
If mDisabledItems.Contains(MyBase.Items.Item(e.Index) )
Then
oTextBrush =
System.Drawing.SystemBrushes.InactiveCaption
Else
oTextBrush = System.Drawing.SystemBrushes.ControlText
End If
End If
e.Graphics.DrawString(MyBase.Items.Item(e.Index), Me.Font,
oTextBrush, e.Bounds.X, e.Bounds.Y)
End Sub

Private Sub InitializeComponent()
MyBase.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
MyBase.DropDownStyle = ComboBoxStyle.DropDownList
End Sub

Public Shadows ReadOnly Property DrawMode() As DrawMode
Get
Return MyBase.DrawMode
End Get
End Property

Public Shadows ReadOnly Property DropDownStyle() As ComboBoxStyle
Get
Return MyBase.DropDownStyle
End Get
End Property

Protected Overrides Sub OnSelectedIndexChanged(ByVal e As
System.EventArgs)
If Me.SelectedIndex <> -1 Then
If
mDisabledItems.Contains(MyBase.Items.Item(Me.Selec tedIndex)) Then
MyBase.SelectedIndex = mPreviousIndex
Else
mPreviousIndex = MyBase.SelectedIndex
End If
End If
End Sub
End Class
--end AdvancedComboBox.vb--

--begin ExampleUsage.vb--
Dim oAdvancedComboBox As New AdvancedComboBox() ' Duh
oAdvancedComboBox.Items.Add("One")
oAdvancedComboBox.Items.Add("Two")
oAdvancedComboBox.Items.Add("Three")
oAdvancedComboBox.Items.Add("Four")

oAdvancedComboBox.DisabledItems.Add("Two")
--end ExampleUsage.vb--
Rgds,

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: BigJay | last post by:
I am 1. trying to have a combobox used as a selector to display records in a subform. and not sure on how to get selected info into subform.the combo is populated but can not get subform updated...
4
by: meganrobertson22 | last post by:
Hi Everyone- I have a question about how to add and then use the "All" selection in a combo box. I am trying to figure out how to: (1) add "All" as a selection to a combo box and then (2)...
7
by: Doug | last post by:
Hi I have a combo box (A) that populates a following combo box (B) based on a selection. The selection from the first combo box (A) initiates an OleDbDataAdapter routine that extracts the...
3
by: hmiller | last post by:
Hey everyone, I am having a hell of a time trying to set this menu system up. Here's what I'm trying to do. Combo Box One; is populated by names under properties "row source" "Phase 1"...
5
by: Ant | last post by:
Hi, (Winform VS2003) I have a combo box bound to a typed data set. When the form loads, the combo box is popluated using a method containing the simple code below: ------------------------...
4
Rabbit
by: Rabbit | last post by:
Cascading Combo/List Boxes This tutorial is to guide you in the creation of Cascading combo/list boxes. That is when you have multiple combo/list boxes where the selection of an option in one...
6
by: Dave | last post by:
I want to put the information that the user selects in my combo boxes into a subform that lies on the same form as the combo boxes. Thanks for your help already, Dave
1
by: didihynes | last post by:
Hi Guys, I'm in desparate need of help. I am producing a database for my dissertation and have got majorly stuck. I am currently creating a form in which the user will select a student from a...
3
kcdoell
by: kcdoell | last post by:
I have 5 cascading combo boxes on a form. Below is a sample of my vb in the first combo box: Private Sub CboDivision_AfterUpdate() 'When the Division is selected, the appropriate Segment...
0
by: dudeja.rajat | last post by:
On Sat, Aug 30, 2008 at 2:32 PM, Fredrik Lundh <fredrik@pythonware.comwrote: Fredrik, Thanks so much. That worked. Following this, I can now see that my combo2 has no previous elements and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.