Private Sub DataGridView1_SelectionChanged(ByVal sender As Object, _ ByVal e As EventArgs) Handles DataGridView1.SelectionChanged DataGridView2.ClearSelection() End Sub Private Sub DataGridView2_SelectionChanged(ByVal sender As Object, _ ByVal e As EventArgs) Handles DataGridView2.SelectionChanged DataGridView1.ClearSelection() End Sub
'修正前 Public Class Form1 Private ds As New DataSet() Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load Dim tbl As DataTable = ds.Tables.Add("Table1") tbl.Columns.Add("Col1", GetType(Integer)) For r As Integer = 1 To 20 tbl.Rows.Add(r) Next DataGridView1.DataSource = ds DataGridView1.DataMember = "Table1" DataGridView2.DataSource = ds DataGridView2.DataMember = "Table1" End Sub End Class
'修正後 Public Class Form1 Private ds As New DataSet() Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load Dim tbl As DataTable = ds.Tables.Add("Table1") tbl.Columns.Add("Col1", GetType(Integer)) For r As Integer = 1 To 20 tbl.Rows.Add(r) Next BindingSource0.DataSource = ds BindingSource1.DataSource = BindingSource0 BindingSource1.DataMember = "Table1" DataGridView1.DataSource = BindingSource1 BindingSource2.DataSource = BindingSource0 BindingSource2.DataMember = "Table1" DataGridView2.DataSource = BindingSource2 End Sub End Class
Private Sub DataGridView1_Enter(ByVal sender As Object, _ ByVal e As EventArgs) Handles DataGridView1.Enter DataGridView1.DefaultCellStyle.SelectionBackColor = SystemColors.Highlight DataGridView1.DefaultCellStyle.SelectionForeColor = SystemColors.HighlightText End Sub Private Sub DataGridView1_Leave(ByVal sender As Object, _ ByVal e As EventArgs) Handles DataGridView1.Leave DataGridView1.DefaultCellStyle.SelectionBackColor = DataGridView1.DefaultCellStyle.BackColor DataGridView1.DefaultCellStyle.SelectionForeColor = DataGridView1.DefaultCellStyle.ForeColor End Sub
Private Sub DataGridView1_Enter(ByVal sender As Object, _ ByVal e As EventArgs) Handles DataGridView1.Enter DataGridView1.DefaultCellStyle.SelectionBackColor = SystemColors.Highlight DataGridView1.DefaultCellStyle.SelectionForeColor = SystemColors.HighlightText End Sub Private Sub DataGridView1_Leave(ByVal sender As Object, _ ByVal e As EventArgs) Handles DataGridView1.Leave DataGridView1.DefaultCellStyle.SelectionBackColor = SystemColors.ButtonFace DataGridView1.DefaultCellStyle.SelectionForeColor = SystemColors.ControlText