PC Review


Reply
Thread Tools Rate Thread

DataGridView Databinding issue

 
 
crm
Guest
Posts: n/a
 
      29th Dec 2006
I have two interfaces InterfaceA, and InterfaceB.
InterfaceA has a readonly integer property, and a string description
("ID" and "Description" respectively..
InterfaceB has a couple miscellaneous properties and inherits from
InterfaceA.
I'm trying to create a DataGridView that will allow me to edit a list
of InterfaceA items. Everything works fine if the object I pass in only
implements InterfaceA; but if I use InterfaceB, I get an error when
clearing the datagridView:

' Assign a datasource to the combobox in the only
datagridviewcolumn
Public Sub SetListSource(ByVal values As List(Of InterfaceA))
Me.ListColumn.DisplayMember = "Description"
Me.ListColumn.ValueMember = "ID"
Me.ListColumn.ValueType = GetType(Integer)
Me.ListColumn.ReadOnly = False
Me.ListColumn.DataSource = values
End Sub

' populate the rows of the datagridviewcolumn
Public Sub SetDataSource(ByVal list As (Of InterfaceA))
Me.DataGridView.Rows.Clear()

For Each item As ICharge In list
Me.DataGridView.Rows.Add(item.ID)
Next
End Sub

I've written the following unit test as well:
Dim source as IList(of InterfaceA) = GetList()
Dim e As New InterfaceAEditor
e.SetListSource(source)
e.SetDataSource(source)

WHen I run the unit test, I get the following error:
failed: System.ArgumentException : Field called Description does not
exist.
at
System.Windows.Forms.DataGridViewComboBoxCell.InitializeDisplayMemberPropertyDescriptor(String
displayMember)
at
System.Windows.Forms.DataGridViewComboBoxCell.OnDataGridViewChanged()
at System.Windows.Forms.DataGridViewRowCollection.AddInternal(Boolean
newRow, Object[] values)
at System.Windows.Forms.DataGridView.AddNewRow(Boolean
createdByEditing)
at
System.Windows.Forms.DataGridView.OnRowCollectionChanged_PostNotification(Boolean
recreateNewRow, Boolean allowSettingCurrentCell, CollectionChangeAction
cca, DataGridViewRow dataGridViewRow, Int32 rowIndex)
at
System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged_PostNotification(CollectionChangeAction
cca, Int32 rowIndex, Int32 rowCount, DataGridViewRow dataGridViewRow,
Boolean changeIsDeletion, Boolean changeIsInsertion, Boolean
recreateNewRow, Point newCurrentCell)
at
System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged(CollectionChangeEventArgs
e, Int32 rowIndex, Int32 rowCount, Boolean changeIsDeletion, Boolean
changeIsInsertion, Boolean recreateNewRow, Point newCurrentCell)
at
System.Windows.Forms.DataGridViewRowCollection.ClearInternal(Boolean
recreateNewRow)
at System.Windows.Forms.DataGridViewRowCollection.Clear()

The error happens on the call to DataGridView.Clear().
I have no idea why. I would really appreciate any help anyone could
offer.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGridView without databinding? John Wright Microsoft VB .NET 4 16th Nov 2007 04:29 PM
DataGridView DataBinding helpful sql Microsoft Dot NET 9 2nd Jun 2006 02:37 PM
DataGridView DataBinding helpful sql Microsoft C# .NET 9 2nd Jun 2006 02:37 PM
DataGridView DataBinding helpful sql Microsoft VB .NET 9 2nd Jun 2006 02:37 PM
DataBinding DataGridView andre.mens@bennekens.nl Microsoft Dot NET Framework Forms 0 7th Feb 2006 08:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:46 AM.