none
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();
                MessageBox.Show(thePayeeId);
            }

    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?

    Thanks
    Friday, October 31, 2008 6:02 AM

Answers

  • I was using the wrong event and property:

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

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