Combo Box Values

I am trying to assign values to a combo box. However, when I add the values, I get the correct number of items in the combo box, but I don't get the actual value. I just see a blank. If I select the item, I then see it. Here is my code:thisVersion.Items.Add("1.0")I also tried this:thisVersion.Items.AddRange(New Object() {"1.0"})Am I missing something?
[374 byte] By [codefund.com] at [2007-12-16]
# 1
Does anyone know why this is not working properly? Am I missing a property?
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2
put this in the load event of your form and tell me it doesn't work.

Dim Temp As New ComboBox()

Temp.Items.Add("1.0")

Me.Controls.Add(Temp)

I say that, because I'm wondering what else you're doing to that ComboBox, because the one line that you posted should work unless you've done something else to the ComboBox like set databinding members or something like that.

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 3
Well, you can't call Items.Add once you've set the DataSource property (I thought that might be it, too, but went and tried it), so it's not a databinding issue. There must be some other property set on the combo box that's causing the trouble. Could be a color issue, a font issue, or ...
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 4
true about the datasource, but i more meant like setting the displaymember property. or does that do the same thing as setting the datasource?
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 5
Nope, that works OK, although setting DisplayMember without setting DataSource gives you text you really don't want to see in the control. But you can still add items.
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 6
That works fine if there is only one value, what if there are 2 values? How do I do that then? The problem is that the value will appear in the box itself, but it won't appear in the drop-down box.

<a href="http://www.aspalliance.com/jgaylord/errors/drop1.gif">Screen Shot 1</a>
<a href="http://www.aspalliance.com/jgaylord/errors/drop2.gif">Screen Shot 2</a>
<a href="http://www.aspalliance.com/jgaylord/errors/drop3.gif">Screen Shot 3</a>

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 7
Are you actually trying what Erik has been suggesting? I can't see any way that this code would generate the kind of thing your screen shots are showing.

Please take a second and create a new form. Add the following code to the form's load event:
Dim cbo As New ComboBox
Me.Controls.Add(cbo)
cbo.Items.Add("Item1")
cbo.Items.Add("Item2")
cbo.Items.Add("Item3")
cbo.Items.Add("Item4")
cbo.Items.Add("Item5")
This MUST create a combo box with 5 items in the dropdown list. If it doesn't, then you need to reinstall the .NET Framework, because something is totally busted.

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 8
When I add the items, they appear in the dropdown. However, the value does not display. In other words, If I add all 5 items, I will have 5 options in the dropdown, however, they all appear blank. This is not the only machine I've done this on. Here is my code block: If UpdateType = 2 Or UpdateType = 5 Then

'Run through some code

If UpdateType = 5 Then
'Do something else
Else

comboName.Items.Add("1.0")
comboName.Items.Add("1.1")

Try
comboName.SelectedItem = myNodeName(1)
Catch
MessageBox.Show("The data imported is invalid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End IfHere is the code code when comboName is added to the form: '
'comboName
'
Me.comboName.Anchor = (System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right)
Me.comboName.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
Me.comboName.Font = New System.Drawing.Font("Verdana", 6.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.comboName.Location = New System.Drawing.Point(8, 56)
Me.comboName.Name = "comboName"
Me.comboName.Size = New System.Drawing.Size(73, 19)
Me.comboName.TabIndex = 10See, there's nothing special. Can't figure it out for the life of me!

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 9
You didn't notice that you had set the DrawMode property to OwnerDrawFixed? That's not the default, and will cause the behavior you're seeing. If you set the Drawmode property to OnwerDrawFixed, you must provide code for the DrawItem event of the control to display each item. Turn that off, and it should work fine.

If all else fails, it's always a good idea to create a new control, from scratch, and try again, rather than fighting and fighting with it.

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 10
Ken,

Thanks a ton! That worked. I must be rushing too much on this project. It's tax season and I have about 3 projects due shortly for an accounting firm. :|

Jason

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...