Problem with Display/Value Member of combo box RRS feed

  • Question

  • Having problems with combo box Display Member and Value Member.

    Using a typed dataset I have the following:

            private void frmMain_Load(object sender, EventArgs e)
                cmbxPayee.DisplayMember = dataSet.Payee.P_NameColumn.ToString();
                cmbxPayee.ValueMember = dataSet.Payee.P_IdColumn.ToString();
                cmbxPayee.DataSource = dataSet.Payee;

    The combo box is being correctly populated with payee names.

    Later I do:

            private void cmbxPayee_DisplayMemberChanged(object sender, EventArgs e)
                string thePayeeId = cmbxPayee.ValueMember.ToString();

    What is showing in the messageBox is the name of the column (P_Id) not the value of the column (e.g. "D").

    Have I correctly initialised the variable in my frmMain_Load method, and if so, why is the value of the column not being shown?

    Friday, October 31, 2008 6:02 AM


  • I was using the wrong event and property:

      private void cmbxPayee_SelectedValueChanged(object sender, EventArgs e)
                string thePayeeId = cmbxPayee.SelectedValue.ToString();

    This solves the problem
    Friday, October 31, 2008 8:02 AM