please advice me how to do this two combobox with properties
http://img593.imageshack.us/img593/2873/all.gif
Printable View
please advice me how to do this two combobox with properties
http://img593.imageshack.us/img593/2873/all.gif
What do you mean 'with properties'? You catch SelectedIndexChanged event on one combobox and depending on the selected item you populate the second combobox with necessary items. You will probably need some data source where all necessary data will be stored.
You need to have something along the lines of the code below. Example uses two ComboBoxes, cboMaster and cboDetails.
Code:Private Sub Form1_Load() Handles MyBase.Load
Dim Items = From M In _
(<Items>
<Item ID="1">Item 1</Item>
<Item ID="2">Item 2</Item>
</Items>.<Item>) _
Select New With {.ID = M.@ID, .Value = M.Value}
cboMaster.DisplayMember = "Value"
cboMaster.ValueMember = "ID"
cboMaster.DataSource = Items.ToList
End Sub
Private Sub cboMaster_SelectedIndexChanged() Handles cboMaster.SelectedIndexChanged
Dim Details = _
<Details>
<Item><ID>1</ID><Value>Child 1</Value></Item>
<Item><ID>1</ID><Value>Child 2</Value></Item>
<Item><ID>1</ID><Value>Child 3</Value></Item>
<Item><ID>2</ID><Value>Value 1</Value></Item>
<Item><ID>2</ID><Value>Value 2</Value></Item>
</Details>
Dim DetailItems = (From D In Details.<Item> _
Where D.<ID>.Value = cboMaster.SelectedValue.ToString _
Select D.<Value>.Value).ToList
cboDetails.DataSource = DetailItems
cboDetails.SelectedIndex = -1
End Sub
Here is an example, but this is not the recomended way to do this, since all is hard-coded,
but it should help you understand how to populate comboboxes.
You should follow cicatrix's (edit: and kevininstructor's :)) advice and use a data source of some kind!
vb Code:
Option Strict On Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load 'Add manufacturers... Me.manufacturerBox.Items.Add("Apple") Me.manufacturerBox.Items.Add("Nokia") Me.manufacturerBox.Items.Add("HTC") Me.manufacturerBox.Items.Add("SonyEricsson") Me.manufacturerBox.SelectedIndex = 0 End Sub Private Sub manufacturerBox_SelectedIndexChanged(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles manufacturerBox.SelectedIndexChanged Me.modelBox.Items.Clear() Select Case Me.manufacturerBox.Text Case "Apple" Me.modelBox.Items.Add("Iphone 3GS") Me.modelBox.Items.Add("Iphone 4G") Case "Nokia" Me.modelBox.Items.Add("Nokia 3210i") Me.modelBox.Items.Add("Nokia N8") Case "HTC" Me.modelBox.Items.Add("HTC Desire") Me.modelBox.Items.Add("HTC HD2") Case "SonyEricsson" Me.modelBox.Items.Add("X10 Mini") Me.modelBox.Items.Add("X10") End Select Me.modelBox.SelectedIndex = 0 End Sub End Class
In situations like this, the data to populate the controls will usually be coming from a database. You might like to follow the CodeBank link in my signature and check out my thread on Master/Detail Data-binding, which addresses this specifically.
@jmcilhinney
How can i do this using my database on the website...
with my form1 in vb.net 2008
What web site? ComboBoxes are Windows controls. If this is a web application then you would be using DropDownLists, not ComboBoxes. It's important that you provide a FULL and CLEAR description of the issue because we only know what you tell us. Given that there's a ASP.NET forum on this site for ASP.NET questions, we will generally assume that any question posted here is not about ASP.NET unless it specifically says so. We will also assume that, if you say ComboBox, you mean ComboBox and not DropDown list. Albeit belatedly, please provide that FULL and CLEAR description of the problem now.
actually i don't know what kind of application must i use..
here is what i want
1. window form that connect to my site sample combobox when you click combobox it will appear the list from my server or mysql on cpanel sample.
2. i do not know if DropDown list is my need to use.. please advice me
when you see my first post, that list i want but via access on mysql on cpanel