The following code can be used in asp net and net desktop applications.
It is good piece of code for visual basic programmer who are learning the visual basic net programming.
dim mypets() as String = {"Cat","Dog","Mouse","Cow","Horse","emu","chicken"}
combobox1.DataSource=mypets
combobox1.SelectedIndex=0
Binding with the array list
dim mypets as new ArrayList
with mypets
.Add("Cat")
.Add("Dog")
.Add("Mouse")
.Add("Cow")
.Add("Horse")
.Add("emu")
.Add("Chicken")
End With
combobox1.DataSource=mypets
combobox1.SelectedIndex=0
Binding with the dataset where data is filled from the database
private dsPets as new Dataset
First we have to fill the dataset dsPets from the sql server database or any other databases
and then use the following code to bind it to the combobox
With combobox1
.Datasource=dspetss.Tables("Pets")
.Displaymember="PetName"
.ValueMember="PetID"
End With
combobox1.SelectedIndex=0
txtDisplay.Text=ctype(combobox1.SelectedValue,String)
Binding with the dataview where data is filled from the database
private dvPets as new DataView
.Datasource=dspetss.Tables("Pets")
.Displaymember="PetName"
.ValueMember="PetID"
End With
combobox1.SelectedIndex=0
txtDisplay.Text=ctype(combobox1.SelectedValue,String)
Binding with the dataview where data is filled from the database
private dvPets as new DataView
We have to fill up the dataview dvPets from the sql server database or any other database source and then use the following code to bind the combobox.
With combobox1
.Datasource=dvPets
.Displaymember="PetName"
.ValueMember="PetID"
End With
combobox1.SelectedIndex=0
txtDisplay.Text=ctype(combobox1.SelectedValue,String)
With combobox1
.Datasource=dvPets
.Displaymember="PetName"
.ValueMember="PetID"
End With
combobox1.SelectedIndex=0
txtDisplay.Text=ctype(combobox1.SelectedValue,String)
No comments:
Post a Comment