Associating wo values with a como box

nabbyg

Member
Joined
May 10, 2005
Messages
16
Programming Experience
1-3
Hello guys, I am trying to associate "Text" and "value" with a combo box. I was trying to do it via this method:

ComboBox.ValueMember = "Mechanism"

ComboBox.DisplayMember = "RepairItemName"

ComboBox.DataSource = arrTemp

Where arrtemp is an arraylist of objects. Every object has a field called Mechanism and RepairItemName.

For some reason, when I am debugging it and I add wach for "ComboBox" and look into its properties, The DisplayMember field Is empty.

When I opened up the arrtemp, I can see that its made up of objects that have a field named "RepairItemName" . Any ideas on how to do it.

Thanks,
Nabby
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,553
Location
Sydney, Australia
Programming Experience
10+
Can I get a bit more info? When you say that the objects in arrTemp have a field named "RepairItemName", do you mean that they are DataRows with a field with this name or that they are some other type that has a member property or variable with that name?
 

nabbyg

Member
Joined
May 10, 2005
Messages
16
Programming Experience
1-3
hey...first of all thanks for the reply. but i did manage to solve the above problem....the elements in arrtemp is an custom object, with a number of string attributes.. and "RepairItemName" is one of the attributes.

now I am having the same KIND of problem I had before....
I have 2 combo boxes. I fill them using the method I had mentioned above. Another funtionality that I need for the combo boxes.. is that when I choose an item in one box, The items in the other box are supposed and vice versa.

I am using the "Selected Index Changed" event handler for this.. but the problem is.. even when I re-load the combo boxes the "Selected Index Changed" property is activated. This goes into an infinite loop.... is there any other property that I can use for that purpose ?? except than the selected index changed. .....

Is there a way that I can stop the "Selected Index Changed" property from firing when I am loading the combo box. only fre when I m picking values....
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,553
Location
Sydney, Australia
Programming Experience
10+
The SelectedIndexChanged event is raised whenever the value of the SelectedIndex changes and there is nothing you can do about that. In situations like this, I use a form-level boolean variable to determine whether the actions in the event handler are excuted, like this:
VB.NET:
[color=Blue]Private[/color] suppressChangeEvents [color=Blue]As Boolean[/color] = [color=Blue]False[/color]

[color=Blue] Private Sub[/color] ComboBox1_SelectedIndexChanged(...) [color=Blue]Handles[/color] ComboBox1.SelectedIndexChanged
   [color=Blue]If Not Me[/color].suppressChangeEvents
	 [color=Blue]Me[/color].suppressChangeEvents = [color=Blue]True[/color]
 
	 [color=Green]'Perform operations that change the selected index in ComboBox2.[/color]
 
	 [color=Blue]Me[/color].suppressChangeEvents = [color=Blue]False[/color]
   [color=Blue]End If
End Sub
[/color] 
[color=Blue] Private Sub[/color] ComboBox2_SelectedIndexChanged(...) [color=Blue]Handles[/color] ComboBox2.SelectedIndexChanged
   [color=Blue]If Not Me[/color].suppressChangeEvents
	 [color=Blue]Me[/color].suppressChangeEvents = [color=Blue]True[/color]
 
	 [color=Green]'Perform operations that change the selected index in ComboBox1.[/color]
 
	 [color=Blue]Me[/color].suppressChangeEvents = [color=Blue]False[/color]
   [color=Blue]End If[/color]
[color=Blue]End Sub[/color]
 

nabbyg

Member
Joined
May 10, 2005
Messages
16
Programming Experience
1-3
The Idea is working like a charm. Thanks Alot for the Help. You are a genius.....Is there anything I can do to give you a good rating or something
 

nabbyg

Member
Joined
May 10, 2005
Messages
16
Programming Experience
1-3
Hey... Ok I have another Problem now....

I am comparing the items in a checklist box to another list of items. If certain conditions are stified then I m setting then I am setting an item as checked (programmatically) in the Checklist box.

I put a breakpoint right after I check an item in the checklist box, and then I opened the properties for the checklist box in the debug window.

I saw that the property called CheckedIndices.count = 1.

I even put a breakpoint at the Itemcheck event for that particular checklistbox, and the program does go there when I programatically check an item in the checklistbox.

When the form actually loads, I do not see any checks on the form. Is there some property that I have activate for the checks to be visible ??


VB.NET:
 JobInstrumentCheckList.SetItemCheckState(0, CheckState.Checked)
 
Top Bottom