I've got a list box bound to a Datatable, like this:
lstProjects.Dat aSource = m_oProjectSet.D ataTable
lstProjects.Dis playMember = "ProjectDes c"
lstProjects.Val ueMember = "ProjectID"
I want to pass the ProjectID value (integer) of the selected item in
lstProjects to another function.
I assumed I could reference the integer value of the ProjectID column as
lstProjects.Sel ectedValue, since I set it's ValueMember property to
"ProjectID" . I discovered that SelectedValue returns a DataRowView.
Through trial and error I found that I can get to the integer value with:
lstProjects.Dat aSource.Default View(lstProject s.SelectedIndex ).Item("Project I
D")
or
m_oProjectSet.D ataTable.Defaul tView(lstProjec ts.SelectedInde x).Item("Projec t
ID")
Seems like a lot of code to do something so simple and so common. (I know
it's one line, but it should be shorter, and more intuitive, given that data
binding should make things like this simple.)
Is there a simpler expression that would give me the integer value?
What is the purpose of the ValueMember property, if not that which I tried
to use it?
Thanks!