dropdown column on datagrid of VB.Net

thanks for the reply,i appreciate it so much,but how can i do that in visual basic.net,until now i still can't find the solution.
[134 byte] By [johnsonchua] at [2007-11-18 2:12:55]
# 1 Re: dropdown column on datagrid of VB.Net
Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
#End Region

'Declare dynamic controls
Public WithEvents cbo As New ComboBox()

Private ds As DataSet
Private dt As DataTable

'on a form load fill the grid from ds
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim data_column As DataColumn

' Build the DataSet.
ds = New DataSet()

' Build the Sale table.
dt = New DataTable("Sale")
ds.Tables.Add(dt)

dt.Columns.Add("Item", GetType(String))
dt.Columns.Add("Quantity", GetType(Integer))
dt.Columns.Add("UnitPrice", GetType(Decimal))

data_column = dt.Columns.Add("Total", GetType(Decimal))
data_column.Expression = "Quantity * UnitPrice"

' Populate the table.
Dim sale_data(2) As Object
sale_data(0) = "Cookie"
sale_data(1) = 12
sale_data(2) = 0.25
dt.Rows.Add(sale_data)

sale_data(0) = "Milk"
sale_data(1) = 1
sale_data(2) = 1.25
dt.Rows.Add(sale_data)

sale_data(0) = "Towel"
sale_data(1) = 4
sale_data(2) = 5.95
dt.Rows.Add(sale_data)

' Accept the data.
ds.AcceptChanges()
' Attach the DataGrids to the DataTables.
dg.DataSource = dt
End Sub

'here is combo stuff
Private Sub dg_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dg.MouseUp
'Get size and location of grid cell
Dim cb As New System.Drawing.Rectangle() 'cell bounds

If dg.CurrentCell.ColumnNumber = 2 Then
If Not cbo.Tag = "Open" Then
cb = dg.GetCellBounds(dg.CurrentRowIndex, 2)
cbo.Location = New Point(cb.X, cb.Y)
cbo.Size = New Size(cb.Width, cb.Height)
dg.Controls.Add(cbo)
Try
cbo.Text = dg.Item(dg.CurrentRowIndex, 2)
Catch

End Try
cbo.Tag = "Open"
cbo.BringToFront()
AddHandler cbo.Click, AddressOf cbo_Click
Else
cb = dg.GetCellBounds(dg.CurrentRowIndex, 2)
cbo.Location = New Point(cb.X, cb.Y)
cbo.Size = New Size(cb.Width, cb.Height)
cbo.BringToFront()
cbo.Tag = "Open"
End If
cbo.Show()
End If

End Sub

'fill the combo
Private Sub cbo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbo.Click
'add items to combo
Dim i As Integer

cbo.Items.Clear()
For i = 0 To 3
cbo.Items.Add("x = " & i)
Next i
End Sub
End Class
Iouri at 2007-11-10 3:25:13 >