Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Retrieving the combobox.SelectedValue

$
0
0
I am having a problem with combobox databinding to a dataset.  I do all the necessary things you have to go through to bind the data and that all seems to work well.  ex:

    cboEmployees.DataSource = dsEmployees.Employees
    cboEmployees.DisplayMember = "EmployeeName"
    cboEmployees.ValueMember = "EmployeeID"
    cboEmployee.DataBinding.Add("SelectedValue", dsEmployees.Employee, "EmployeeID")

The problem I am having is when I try to get the value from cboEmployees.SelectedValue.  I expected to get the EmployeeID value associated with the row.  For some reason if I use cboEmployees.SelectedValue it equals a DataRowView object.  Why can't I get the EmployeeID from the selected row?  I've even tried to use cboEmployees.SelectedValue.Item("EmployeeID") it does not work.  This code is flagged as an error if you have Option Strict ON for your project ( which I do because it is a recommended practice).  So how am I supposed to get the selected value? 

Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>