View Single Post
  #3 (permalink)  
Old 01-02-2009, 8:21 AM
Blesson Blesson is offline
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Jan 2009
Age: 23
Posts: 18
Reputation: 17
Blesson is on a distinguished programming path ahead
Unhappy Datagrid Issue

Let me first make my objective clear. I have a datagrid, and the first column is Item Code and it is a combo box. The second column is Item Description and it is Text box. What i want is, when i select an Item code from the combo box, the Item description must be populated correspondingly from the Ms Acesss Databse.

The Name of the colum is Col_ItemCode and name of the Datagrid is Datagrid_Billing.

This is my code
================

Code:
Private Sub dgvEquipments_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles Datagrid_Billing.EditingControlShowing

Dim cb As ComboBox = TryCast(e.Control, ComboBox)

        If cb IsNot Nothing Then

            AddHandler cb.SelectedIndexChanged, AddressOf ComboBox_SelectedIndexChanged
        End If

End Sub


Private Sub ComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

Dim cb As ComboBox = sender

sqlstatement="SELECT ITEM_DESC FROM ITEM_details where item_code='" & Me.Datagrid_Billing.CurrentRow.Cells(0).FormattedValue.ToString()  & "'"

executequery(sqlstatement)

        If cb.SelectedItem IsNot Nothing Then
            Me.Datagrid_Billing.CurrentRow.Cells(Me.Col_ItemDesc.Index).Value = rs.fields(0).value



        Else
            Me.Datagrid_Billing.CurrentRow.Cells(Me.Col_ItemDesc.Index).Value = ""

        End If
    End Sub



The problem is that Me.Datagrid_Billing.CurrentRow.Cells(0).FormattedV alue.ToString() is returning NULL string and so the query fails and causes a run time error.


If it was VB6.0 i would have written it as "Col_ItemCode.text" which would have not caused a problem. But in VB.Net I am unable do that.


Please help me.
Reply With Quote