StillSeeking

Greetings,

I am constructing a user interface that uses the tab control with two tab pages. Both have DataGridViews that are bound when the user loads an object and both have contain a column with the DataGridViewComboBoxCell that are bound with child/parent related binding sources.

If I load dataset and Databind to both DGVs, the one displayed on the first tab page shows fine. When I click on the second tab page, I get an error that the "DataGridViewComboBoxCell value is not valid". However, if I click on the second tab before it is bound to any data (thus painting the control) then load the dataset and bind the controls, I do not get the error.

The problem seems to be related to the DataGridViewComboBoxCell because when I replace the column with a Text Cell, the application works fine.

Has anyone experienced this problem Many thanks in advance for any insights.



Re: Windows Forms Data Controls and Databinding Strange problem with DataGridViewComboBoxCell

Zhi-Xin Ye - MSFT

How do you bind the DataGridViews Pose some code please.






Re: Windows Forms Data Controls and Databinding Strange problem with DataGridViewComboBoxCell

StillSeeking

I am using a user control and a couple different classes in a MVP pattern, so it is difficult to post code and have it make any sense, but I will try:

- The DataGridView is bound to a Binding Source that I added through the designer. The Binding Source's data source and data member properties are set to a typed dataset and datatable respectively. The table is for "Addresses".

- The DataGridViewComboBoxColumn is also bound through a designer-created Binding Source that has its DisplayMember assigned to a description and the ValueMember assigned to an ID (which is for "AddressTypes")

- I load the ComboBoxColumn' BindingSource with its data when the application loads.

- In my view class, I expose the DataSource property of the BindingSources in the following way:

Public Property Addresses() As dsCore.AddressesRow()

Get

Return Me.cntrlAddresses.AddressesBindingSource.DataSource

End Get

Set(ByVal value As dsCore.AddressesRow())

Me.cntrlAddresses.AddressesBindingSource.DataSource = value

End Set

End Property

In my presenter class, when the selected person changes, I call a routine that clears the binding source with the following code:

If Me.cntrlAddresses.AddressesBindingSource.Count <> 0 Then Me.cntrlAddresses.AddressesBindingSource.Clear()

Then I load my dataset and assign the above property :

Me.View.Addresses = MyDatasource.Load(PersonData, PersonID) ' "Load" Returns an array of AddressRows

I hope this makes sense.





Re: Windows Forms Data Controls and Databinding Strange problem with DataGridViewComboBoxCell

StillSeeking

Solved the problem by being a little more purposeful in my databinding. It basically was something like this:

Private _addressTypes As AddressTypesDataTable

Public Property AddressTypes() As AddressTypesDataTable

Get

Return Me.cntrlAddresses.AddressTypeBindingSource.DataSource

End Get

Set(ByVal value As AddressTypesDataTable)

Me._addressTypes = value

Me.cntrlAddresses.AddressTypeBindingSource.DataSource = _addressTypes

End Set

End Property