473,804 Members | 4,217 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1909
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 "AdvancedComboB ox" 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 AdvancedComboBo x.vb--
Public Class AdvancedComboBo x
Inherits Windows.Forms.C omboBox

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

Public Sub New()
MyBase.New()
MyBase.DrawMode = System.Windows. Forms.DrawMode. OwnerDrawFixed
MyBase.DropDown Style = ComboBoxStyle.D ropDownList
End Sub

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

Private Sub AdvancedComboBo x_DrawItem(ByVa l sender As Object,
ByVal e As System.Windows. Forms.DrawItemE ventArgs) Handles
MyBase.DrawItem
If e.Index = -1 Or e.Index > MyBase.Items.Co unt - 1 Then
e.DrawBackgroun d()
Exit Sub
End If

Dim oTextBrush As Brush
If e.State And DrawItemState.S elected Then
If mDisabledItems. Contains(MyBase .Items.Item(e.I ndex))
Then
oTextBrush =
System.Drawing. SystemBrushes.I nactiveCaption
Else
e.DrawBackgroun d()
oTextBrush =
System.Drawing. SystemBrushes.H ighlightText
End If
Else
e.DrawBackgroun d()
If mDisabledItems. Contains(MyBase .Items.Item(e.I ndex))
Then
oTextBrush =
System.Drawing. SystemBrushes.I nactiveCaption
Else
oTextBrush = System.Drawing. SystemBrushes.C ontrolText
End If
End If
e.Graphics.Draw String(MyBase.I tems.Item(e.Ind ex), Me.Font,
oTextBrush, e.Bounds.X, e.Bounds.Y)
End Sub

Private Sub InitializeCompo nent()
MyBase.DrawMode = System.Windows. Forms.DrawMode. OwnerDrawFixed
MyBase.DropDown Style = ComboBoxStyle.D ropDownList
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.DropDown Style
End Get
End Property

Protected Overrides Sub OnSelectedIndex Changed(ByVal e As
System.EventArg s)
If Me.SelectedInde x <> -1 Then
If
mDisabledItems. Contains(MyBase .Items.Item(Me. SelectedIndex)) Then
MyBase.Selected Index = mPreviousIndex
Else
mPreviousIndex = MyBase.Selected Index
End If
End If
End Sub
End Class
--end AdvancedComboBo x.vb--

--begin ExampleUsage.vb--
Dim oAdvancedComboB ox As New AdvancedComboBo x() ' Duh
oAdvancedComboB ox.Items.Add("O ne")
oAdvancedComboB ox.Items.Add("T wo")
oAdvancedComboB ox.Items.Add("T hree")
oAdvancedComboB ox.Items.Add("F our")

oAdvancedComboB ox.DisabledItem s.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
2972
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 when selection is made..... 2. I also want to use one combo box to select a second set of criteria in a second combo box that is then used to refine displayrd records in a a subform.... am afraid im lost on this..??? I have a main table that...
4
7196
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) how to use the selection "All" as criteria for a field in a query, which is used to generate data for a report.
7
11146
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 values for the second combo box (B) from a database. However, when I choose a value from the first combo box (A), the second combo box (B) populates as required, but if i change my mind about the selection from the first combo box (A) , the second...
3
3658
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" through "Phase 10" (there are 10 Phases I want to sort from) Once the phase has been selected a second combo box would populate.
5
2253
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: ------------------------ // Fill the datasets for the combo boxes daDepartment.Fill(dsDepartment.Departments);
4
64653
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 determines the available options in the other. TERMINOLOGY Row Source: The table/query from which the Combo Box or List Box gets its values. Note: There are other types of row sources that can be used but for simplicity we will stick with Tables...
6
3685
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
2522
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 combo box, which that selection populates the next combo for the course selection. I have managed to do that with the coding shown below, my next combo will work from the course selection to bring back the feedback topics associated with that course,...
3
3989
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 list will 'display in the drop down list of CboSegment With Me! If IsNull(Me!cboDivision) Then
0
1617
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 contains only the elements relevant to selection in combo1. Now, as soon as I select something in combo 2 and go back to change selection in combo1 the combo2 must get its history cleared up (i.e the previous selection in combo2's entry subwidget)
0
9585
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7622
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5658
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2997
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.