DataGridViewComboBoxCell unable to populate datasource

Answered
0
0

Hi all,

as described in the title i’m unable to populate datasource of DataGridViewComboBoxCell.

No items are displayed, seems that datasource is not send to the client or not load.

I attach a little sample (WisejDGV.zip).

 

Can somebody helps ?

Thanks

 

Wisej 1.5.23.0

Visual Studio 15.8.7

 

UPDATE

Seems the problem is related to a UserControl. If I use the same logic on a Window there is no problem.

I attach the sample updated (WisejDGV2.zip).

 

  • You must to post comments
Best Answer
1
0

See attached fixed app. It shows the problem and the fix in Wisej and WinForms.

The problem is that when you assign the data source in the Load event you can’t use the rows right away when it’s in a user control. The same happens in WinForms (your sample doesn’t work in winforms as well). The DGV data binding implementation may populate the rows several times depending on the binding context changed event. You should use the DataBindingComplete event.

The same happens if you change colors right after assigning the data source in a child of a child. When the binding context changes the rows are recreated and your changes are lost. If you use the DataBindingComplete event it works well.

 

 

  • Luca (ITG)
    Forgot to add. The image shows 3 grids: 1 grid in window, 2 grid in user control not using databindingcomplete, 3 fixed user control. Notice also that there is no need to use the Refresh, Update or BeginUpdate calls.
  • You must to post comments
0
0

Hi Luca,

thanks for help, very complete answer!

  • You must to post comments
0
0

Hi Tiago,

yes it’s correct your suggestion, but what i posted is a sample from my working project where I need to set different DataSource for DataGridViewComboBox on every line. That’s why the sample is setting it on every line. In my working project i have no problem doing that on a Window with DataGridViewComboBox, but using a UserControl no datasource is set.

 

Thanks for any further suggestion.

 

UPDATE

Note that also trying to set background color for row, no color is set. Seems that the DataGridView in the UserControl is not updating.

I attach the sample updated (WisejDGV3.zip).

 

Attachment
  • You must to post comments
0
0

Hi Simone,

When using a ComboBox column in a DGV, the ComboBox data source should be specified just once. Your original project was specifying the ComboBox data source on every row.

Please find attached your project fixed and converted to WinForms.

There is a DataBinding example in GitHub but it doesn’t show an example of a ComboBox column. It will be updated.

 

Attachment
  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.