Placing ComboxBox in DataGrid Cell is a task usually found in Invoicing application. Here is my version of same.

Imports System.Data.SqlClient
Public Class Form1
    Dim cn As SqlConnection
    Dim cmd As SqlCommand
    Dim da As SqlDataAdapter
    Dim dr As SqlDataReader
    Dim ds As New DataSet

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cn = New SqlConnection("Integrated Security=sspi;Initial Catalog =ShalvinPD;Data Source = .\sqlexpress")
        da = New SqlDataAdapter("select ProductName,Categoryid ,UnitPrice from Products", cn)
        da.Fill(ds, "products")
        DataGrid1.SetDataBinding(ds, "products")
    End Sub

    Private Sub DataGrid1_CurrentCellChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
        Dim x, y, w, h As Integer
        Dim rect As Rectangle
        rect = DataGrid1.GetCurrentCellBounds
        x = rect.X + DataGrid1.Left
        y = rect.Y + DataGrid1.Top
        w = rect.Width
        h = rect.Height
        ComboBox1.SetBounds(x, y, w, h)
        ComboBox1.Visible = True
    End Sub
    Private Sub fillcombo()
        cmd = New SqlCommand("select * from categories", cn)
        dr = cmd.ExecuteReader()
        While dr.Read()
        End While
    End Sub

    Private Sub DataGrid1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseDown
        MessageBox.Show(e.X.ToString() + " " + e.Y.ToString() + " " + e.Button.ToString())
    End Sub
End Class

Happy Programming
9 Years
Discussion Span
Last Post by debashishm

i am using vb.net for the first time...can any one of u help me in how to add values from the database and display it into a textbox.
the columns afr bill_no((varchar)not a primary key), customer_no and prod_amount(money).

please help

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.