Home  • Programming • C#.NET

DisplayMember and ValueMember Attribute in ComboBox

datatable-table-new-columns
DataTable table = new DataTable();
table.Columns.Add("operator", typeof(string));
table.Columns.Add("name", typeof(string));
        
// Here we add five DataRows.
table.Rows.Add("+", "Sum");
table.Rows.Add("-", "Subtract");
table.Rows.Add("/", "Divide");
table.Rows.Add("*", "Multiply");
       
cmbOperator.DataSource=table;
cmbOperator.DisplayMember="name";
cmbOperator.ValueMember="operator";

txtDisplay.Text = cmbOperator.SelectedValue.ToString();

Comments 0


Share

Copyright © 2024. Powered by Intellect Software Ltd