I use a Form with a Datagridview-Control (DataGridConn), a Datatable (Testtab) and a Bindingsource (Conn). When I add a new row in the Grid and want to set some starting values (XXXX) in the Conn_AddingNew event I get the error:
Objects added to a BindingSource's list must all be of the same type.
The used code is the following:
Public
Conn =
New BindingSourceTestTab =
New DataTableTestTab.Columns.Add(
New DataColumn("NAME", GetType(String)))Conn.DataSource = TestTab
DataGridConn.DataSource = Conn
For i = 0 To 10TestTab.Rows.Add(TestTab.NewRow)
TestTab.Rows(i)(
"NAME") = "NAME" & CStr(i) Next End Sub Private Sub Conn_AddingNew(ByVal sender As Object, ByVal e As System.ComponentModel.AddingNewEventArgs) Handles Conn.AddingNew Dim dr As DataRow = TestTab.NewRowdr(
"NAME") = "XXXXX"e.NewObject = dr
End Subend ClassI would be very grateful to get any help for this problem
Best regards
Klaus Unterforsthuber

Error Bindingsource
Masroor ul Hassan
hi,
i think you don't have to assign the default value to your binding source you can achieve it during creation of your table like this
Public
Class Form1 Dim Conn As BindingSource Dim TestTab As DataTable
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim i As IntegerConn =
New BindingSourceTestTab =
New DataTable Dim NameCol As New DataColumn With NameCol.DataType =
GetType(String) 'here you can assign a value to the new row.DefaultValue =
"xxxxx".ColumnName =
"name" End WithTestTab.Columns.Add(NameCol)
Conn.DataSource = TestTab
DataGridconn.DataSource = Conn
For i = 0 To 10TestTab.Rows.Add(TestTab.NewRow)
TestTab.Rows(i)(
"NAME") = "NAME" & CStr(i) Next
End SubEnd
Classhope it helpls
Raymond Roelands
I found out that it has to be a DataRowView in this particular case.
Regards, HalH
BreSmith
Klaus,
I have the same problem.
Did you solve it
Regards, HalH.