•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 363,779 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,461 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser:
Placing ComboxBox in DataGrid Cell is a task usually found in Invoicing application. Here is my version of same.
Last edited : Mar 26th, 2008.
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") cn.Open() da = New SqlDataAdapter("select ProductName,Categoryid ,UnitPrice from Products", cn) da.Fill(ds, "products") DataGrid1.SetDataBinding(ds, "products") fillcombo() 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() ComboBox1.Items.Add(dr("categoryName")) 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
Post Comment
•
•
•
•
DaniWeb Marketplace (Sponsored Links)