回复 3 楼 worte
Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim mycon As New SqlConnection("data source=192.168.1.85;initial catalog=prod;Persist Security Info=True;user id=sa;password=sa;")
Dim sqltxt As String = "select * from Products"
If mycon.State = ConnectionState.Closed Then mycon.Open()
Dim ds As New DataSet
Dim da As SqlDataAdapter
da = New SqlDataAdapter(sqltxt, mycon)
da.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
mycon.Close()
mycon = Nothing
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub DataGridView1_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEnter
With Me.DataGridView1
.Controls.Clear()
If .Rows.Count > 0 Then
Dim GH As Integer = .CurrentCell.ColumnIndex
Dim GF As Integer = .CurrentCell.RowIndex
If GH = 1 Then
.Controls.Add() ';//dataGr
= .Item(1, GF).Value.ToString.Trim
= .GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, True).Width ';//获取单元格高并设置为btn的宽
' = .GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, True).Height ';//获取单元格高并设置为btn的高
= New System.Drawing.Point(((.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, True).Right) - ()), .GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, True).Y) ';//设置btn显示位置
End If
End If
End With
End Sub
Private Sub DataGridView1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseWheel
Me.DataGridView1.Controls.Clear()
End Sub
Private Sub DataGridView1_Scroll(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles DataGridView1.Scroll
Me.DataGridView1.Controls.Clear()
End Sub
End Class
ComboBox1 加上数据
我是这样处理的
[
本帖最后由 jianjunfeng 于 2014-6-4 19:39 编辑 ]