[SOLVED] Combobox Column Issue in datagridview

Answered
0
0

I have a problem with my combobox in datagrid, instead of displaying the data from my model list, it is showing the classname, please see attached project.

  • You must to post comments
Best Answer
0
0

Hi Glenn,

#1927 is fixed in our latest Wisej build (2.0.32).

Best regards
Frank

  • You must to post comments
0
0

That’s because you are not setting the DisplayMember so Wisej displays the result of ToString().

In your sample you set the DisplayMember on the Column but don’t set the data source, then when the control is shown you set the datasource directly on the combobox used in the cell without the DisplayMember. Change your code like this:

  • Delete DataGridView1_EditingControlShowing, it’s not necessary for the binding and you don’t need to set the datasource every time the cell is in edit mode.
  • Add this.Column0.DataSource = list; in Page1_Load.

 

  • You must to post comments
0
0

Thanks, but I have another problem, when I type in a value that is not in the list, it gives me an error “new value” cannot be converted to system.string.

 

Thanks.

  • You must to post comments
0
0

Unfortunately the second problem you mentioned is a bug/regression (#1927). This is a quick workaround.

private void DataGridView1_CellParsing(object sender, DataGridViewCellParsingEventArgs e)
{
   e.ParsingApplied = true;
}

private void DataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
   e.Cancel = false;
}

Th fix will be available in this upcoming build (early next week).

 

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.