|
-
October 11th, 2009, 02:13 PM
#1
DatagridViewComboboxColumn displays ValueMember in stead of DisplayMember
Hi,
I bind my datagridview to a bindingsource at runtime. I manually add an
extra DataGridViewComboBoxColumn to the datagridview, which I bind to another
datatable that is not in the datasource. When I select a value in the
DataGridViewComboBoxColumn then it first displays the DisplayMember but when
I leave the cell it displays the ValueMember. In my opinion the cell should
display the DisplayMember. What am I missing?
dgvTransacties.DataSource = bsTransacties;
DataGridViewComboBoxColumn newCol = new DataGridViewComboBoxColumn();
newCol.DataSource = ds.Tables["Rubriek"];
newCol.DisplayMember =
ds.Tables["Rubriek"].Columns["Uitgavepost"].ColumnName;
newCol.ValueMember = ds.Tables["Rubriek"].Columns["Id"].ColumnName;
newCol.DataPropertyName =
ds.Tables["Transactie"].Columns["Post"].ColumnName;
newCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
dgvTransacties.Columns.Add(newCol);
Thnx
hjs
-
May 14th, 2012, 06:06 PM
#2
Re: DatagridViewComboboxColumn displays ValueMember in stead of DisplayMember
I am trying to have a "DataGridViewComboBoxColumn" with a displaymember and a valuemember.
Can someone please give me a simple C# example of a "DataGridViewComboBoxColumn" using a displaymember and a valuemember.
DataGridViewComboBoxColumn cbCol = new DataGridViewComboBoxColumn();
cbCol.FlatStyle = FlatStyle.Popup;
cbCol.Items.Clear();
foreach (DataRow dr in new functions_sqls().select("select distinct l.list_value vm, l.long_description dm from lists l").Rows)
{
cbCol.Items.Add(dr[0].ToString());
}
cbCol.Name = "lt_unit_of_measure_product";
dgv1.Columns.Add(cbCol);
dgv1.DataSource = new functions_sqls().select("select top 5 lt_unit_of_measure_product from products");
DataTable ds = new functions_sqls().select("select distinct l.list_value vm, l.long_description dm from lists l");
((DataGridViewComboBoxColumn)dgv1.Columns[0]).DataSource = ds;
((DataGridViewComboBoxColumn)dgv1.Columns[0]).ValueMember = "vm";
((DataGridViewComboBoxColumn)dgv1.Columns[0]).DisplayMember = "dm";[0]).DisplayMember = "dm";
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|