Y
Young J. Putt
I've got a list box bound to a Datatable, like this:
lstProjects.DataSource = m_oProjectSet.DataTable
lstProjects.DisplayMember = "ProjectDesc"
lstProjects.ValueMember = "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.SelectedValue, 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.DataSource.DefaultView(lstProjects.SelectedIndex).Item("ProjectI
D")
or
m_oProjectSet.DataTable.DefaultView(lstProjects.SelectedIndex).Item("Project
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, assuming that
databinding 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 for doing what I
tried to do?
Thanks!
lstProjects.DataSource = m_oProjectSet.DataTable
lstProjects.DisplayMember = "ProjectDesc"
lstProjects.ValueMember = "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.SelectedValue, 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.DataSource.DefaultView(lstProjects.SelectedIndex).Item("ProjectI
D")
or
m_oProjectSet.DataTable.DefaultView(lstProjects.SelectedIndex).Item("Project
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, assuming that
databinding 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 for doing what I
tried to do?
Thanks!