日期:2014-05-18 浏览次数:20853 次
Public Class Form1 Private DataGridView1 As New DataGridView Private ComboBox1 As New ComboBox Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AddHandler DataGridView1.CellClick, AddressOf DataGridView1_CellClick AddHandler ComboBox1.TextChanged, AddressOf ComboBox1_TextChanged Me.DataGridView1.AllowUserToResizeRows = False Me.DataGridView1.AllowUserToResizeColumns = False Me.DataGridView1.Dock = DockStyle.Fill Me.DataGridView1.Columns.Add("Column1", "Column1") Me.DataGridView1.Columns.Add("Column2", "Column2") For i As Integer = 1 To 3 Me.DataGridView1.Rows.Add("Row" + i.ToString + " Column1", "Row" + i.ToString + " Column2") Next For i As Integer = 0 To 10 Me.ComboBox1.Items.Add("Item" + i.ToString) Next Me.ComboBox1.Visible = False Me.Controls.Add(ComboBox1) Me.Controls.Add(DataGridView1) End Sub Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) If e.ColumnIndex = 1 Then Dim p As Point = Me.DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, True).Location p.Offset(Me.DataGridView1.Left, Me.DataGridView1.Top) Me.ComboBox1.Location = p Me.ComboBox1.Size = Me.DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, False).Size Me.ComboBox1.Visible = True Else Me.ComboBox1.Visible = False End If End Sub Private Sub ComboBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Me.DataGridView1.CurrentCell.Value = Me.ComboBox1.Text Me.ComboBox1.Visible = False End Sub End Class
------解决方案--------------------
2楼的差不多吧,就是要动态地去计算一下用户鼠标点击的位置位于当前哪一行哪一列,再计算出该单元格的位置及大小,然后显示出来~
------解决方案--------------------
系统自带的listview没有这个功能,建议LZ可以用datagridview,baidu一下,有很多的