944,159 Members | Top Members by Rank

Ad:
  • VB.NET Code Snippet
  • Views: 6536
  • VB.NET RSS
0

Placing ComboxBox in DataGrid Cell -Visual Basic .Net Windows Forms

by on Feb 21st, 2008
Placing ComboxBox in DataGrid Cell is a task usually found in Invoicing application. Here is my version of same.
VB.NET Code Snippet (Toggle Plain Text)
  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
Comments on this Code Snippet
Jan 26th, 2011
0

Re: Placing ComboxBox in DataGrid Cell -Visual Basic .Net Windows Forms

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
Newbie Poster
debashishm is offline Offline
1 posts
since Jan 2011
Message:
Previous Thread in VB.NET Forum Timeline: IndexOutOfRangeException was unhandled
Next Thread in VB.NET Forum Timeline: Dinamically change font size... on runtine!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC