User Name Password Register
DaniWeb IT Discussion Community
All
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:
Feb 21st, 2008
Views: 1,294
Placing ComboxBox in DataGrid Cell is a task usually found in Invoicing application. Here is my version of same.
Last edited : Mar 26th, 2008.
visualbasicnet Syntax | 3 stars
  1. Imports System.Data.SqlClient
  2. Public Class Form1
  3. Dim cn As SqlConnection
  4. Dim cmd As SqlCommand
  5. Dim da As SqlDataAdapter
  6. Dim dr As SqlDataReader
  7. Dim ds As New DataSet
  8.  
  9.  
  10. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  11. cn = New SqlConnection("Integrated Security=sspi;Initial Catalog =ShalvinPD;Data Source = .\sqlexpress")
  12. cn.Open()
  13. da = New SqlDataAdapter("select ProductName,Categoryid ,UnitPrice from Products", cn)
  14. da.Fill(ds, "products")
  15. DataGrid1.SetDataBinding(ds, "products")
  16. fillcombo()
  17. End Sub
  18.  
  19.  
  20. Private Sub DataGrid1_CurrentCellChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
  21. Dim x, y, w, h As Integer
  22. Dim rect As Rectangle
  23. rect = DataGrid1.GetCurrentCellBounds
  24. x = rect.X + DataGrid1.Left
  25. y = rect.Y + DataGrid1.Top
  26. w = rect.Width
  27. h = rect.Height
  28. ComboBox1.SetBounds(x, y, w, h)
  29. ComboBox1.Visible = True
  30. End Sub
  31. Private Sub fillcombo()
  32. cmd = New SqlCommand("select * from categories", cn)
  33. dr = cmd.ExecuteReader()
  34. While dr.Read()
  35. ComboBox1.Items.Add(dr("categoryName"))
  36. End While
  37. End Sub
  38.  
  39. Private Sub DataGrid1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseDown
  40. MessageBox.Show(e.X.ToString() + " " + e.Y.ToString() + " " + e.Button.ToString())
  41. End Sub
  42. End Class
  43.  
  44.  
  45. Happy Programming
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 10:34 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC