Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
275
DisplayValue and DisplayMember Not Working
posted

I have an UltraCombo that's filled with the following:

public void Fill(){

SqlConnection conn = new SqlConnection(@"Data Source=ServerName;Initial Catalog=MyDataBase;User ID=user;Password=xxxxx");
SqlCommand cmd = new SqlCommand();
SqlDataReader MyReader;
cmd.CommandText = @"SELECT Nombre, SubFamilia from dbo.SubFamilia";
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
conn.Open();

MyReader = cmd.ExecuteReader();
DataTable dt = new DataTable();

dt.Load(MyReader);

if(dt.Rows.Count>0){

this.ecSubfamilia.DataSource = dt;
this.ecSubfamilia.DataBind();
this.ecSubfamilia.ValueMember = "SubFamilia";
this.ecSubfamilia.DisplayMember = "Nombre";

}

conn.Close();

}

Then, the method is called when loading a form.

private void UD12Form_Load(object sender, EventArgs args)

{
// Add Event Handler Code
Fill();
}

I use the values to display them on a MessageBox for testing purposes, with a click event on a button.

private void btnActualizar_Click(object sender, System.EventArgs args)
{

MessageBox.Show("This are the values for the combobox you selected: " + ecSubfamilia.ValueMember + " & " + ecSubfamilia.DisplayMember );

}

The MessageBox displays the name of the column "SubFamilia" & "Nombre", not the actual data from the database.

Am I missing something?

Thanks

Parents
No Data
Reply
  • 469350
    Suggested Answer
    Offline posted

    Hi Willam,

    Your MessageBox is displaying the value of the ValueMember and DisplayMember properties. These are string properties and they will return the strings you set them to. So that's correct.

    It think what you probably want is the selected value and the display text of that value. To do that, you simply use the control's Value and Text properties respectively.

    MessageBox.Show("This are the values for the combobox you selected: " + ecSubfamilia.Value + " & " + ecSubfamilia.Text );

Children
No Data