Hi friends,
I am using vb.net 2010 for a project and I need some assistance.
I have datagridview in the project whose datasource is bindingsource.
This datagridview has two lookup columns namely IncomeCombo and AssetCombo. The lookup columns have different bindingsources as their datasources.
Everything works fine but I get error if try to insert records into the datagridview(or the underlying table) manually.
The error is raised by the lookup columns. The error raised is invalid column in IncomeCombo. But the data assigned to the lookup columns are valid. I have double checked that.
I have tried all that I could but to no avail. I have tried to insert the records into the underlying table as well as suspendingbinding.
I below are my codes for your perusal.
Properties of the lookups:
With incomecombo
.HeaderText = "Exp/Inc Account (DR)"
.DataSource = Me.IncExpBindingSource
.DisplayMember = "acctname"
.DataPropertyName = "acctdebited"
.ValueMember = "acctid"
.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing
.MinimumWidth = 100
.Width = 175
End With
With assetcombo
.HeaderText = "Asset Account (CR)"
.DataSource = Me.AssetBindingSource
.DisplayMember = "acctname"
.DataPropertyName = "acctcredited"
.ValueMember = "acctid"
.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing
.MinimumWidth = 100
.Width = 175
End WithRoutine for inserting record:
If recTable.Rows.Count <> 0 Then
For Each r As DataRow In recTable.Rows
dgExpenditure.AllowUserToAddRows = False
NewExpBindingSource.AddNew()
'NewExpBindingSource.SuspendBinding()
Dim i As Integer = dgExpenditure.Rows.Count - 2
dgExpenditure.Rows(i).Cells("incomeacct").Value = r.Item("incomeacc").ToString.Substring(0, 7).Trim
dgExpenditure.Rows(i).Cells("incomecombo").Value = r.Item("incomeacc")
dgExpenditure.Rows(i).Cells("assetcombo").Value = r.Item("assetacc")
'Dim ddd As String =
'dgExpenditure.Rows(i).Cells("assetacct").Value = r.Item("assetacc").ToString.Substring(0, 7).Trim
dgExpenditure.Rows(i).Cells("amount").Value = r.Item("amount")
dgExpenditure.Rows(i).Cells("dateoccurred").Value = r.Item("dateo")
dgExpenditure.Rows(i).Cells("paytypecombo").Value = r.Item("paytype")
dgExpenditure.Rows(i).Cells("paytype").Value = r.Item("paytype").ToString.Substring(0, 2).Trim
dgExpenditure.Rows(i).Cells("payee").Value = r.Item("payee")
dgExpenditure.Rows(i).Cells("transno").Value = r.Item("transno")
Next
recTable.Clear()
dgExpenditure.AllowUserToAddRows = True
End IfThank for your usual assistance.
PA