Quick Question

  • Thread starter Thread starter Merlin
  • Start date Start date
M

Merlin

Hi Group,

I wonder if somebody would be kind enough to explain something to me or even
point me in the direction of a link?

What is the difference on a combobox's databinding between:

SelectedItem, SelectedValue, Tag, Text, Datasource, & Displaymember.

The Reason I ask is I have 2 x Table, Table 1 has a feild called
AceessLevel, Table 2 has a list of access levels, I would like to be able to
use a combo box to select the Acesslkevel and update the database.

Many Thanks
Merlin
 
There is a sample for you

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Clic
Debug.WriteLine(Me.ComboBox1.Text & " " & Me.ComboBox1.SelectedValue
End Su

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa

Dim arrPerson As New ArrayList(

arrPerson.Add(New Person("æ“作员1", "11")
arrPerson.Add(New Person("æ“作员2", "22")
arrPerson.Add(New Person("æ“作员3", "33")
arrPerson.Add(New Person("æ“作员4", "44")

Me.ComboBox1.DataSource = arrPerso
Me.ComboBox1.DisplayMember = "Name
Me.ComboBox1.ValueMember = "ID

Me.DataGrid1.DataSource = arrPerso
End Su

Public Class Perso

Private _Name As Strin
Private _ID As Strin

Public Sub New(ByVal strName As String, ByVal strID As String
MyBase.New(
Me._Name = strNam
Me._ID = strI
End Su

Public ReadOnly Property Name() As Strin
Ge
Return _Nam
End Ge
End Propert

Public ReadOnly Property ID() As Strin
Ge
Return _I
End Ge
End Propert

End Class
 
Hi,

Merlin in addition to TomYao a short explanation.
SelectedItem,
The selected displaymember item (see below)

SelectedValue,
The selected valuemember item

Tag,
To save some data in the combobox (I never used it)

Text,
The current text in the textbox from the combobox

Datasource,
The source from the data mostly a datatable (as a part of a dataset) or an
array

Displaymember
The column of the datatable to show

Valuemember
The column of the datatable to pick as value

I hope this helps?

Cor
..
 
Back
Top