关于DataGridView的一些小操作(续)

8.取消默认选中行  

  整行选择时:datagridview.SelectedRows(0).Selected = False

 

9.获取选中行某列的值  

Private Sub dgvCheck_Click(ByVal sender As Object, ByVal e As  System.EventArgs) Handles dgvCheck.Click 
        Dim ss As String 
        ss = dgvCheck.SelectedCells.Item(0).Value 
End Sub 

 10.DataGridView的行背景色(奇数行与偶数行的背景色差异)

  


      '全ての列の背景色を水色にする
  DataGridView1.RowsDefaultCellStyle.BackColor = Color.Aqua
  '奇数行を黄色にする
  DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Yellow

 

11.变更列标题名字

  'DataGridView1のはじめの列のテキストを変更する
  DataGridView1.Columns(0).HeaderText = "はじめの列"

12.鼠标指向的单元格颜色变更

  'DataGridView1のCellMouseEnterイベントハンドラ
  Private Sub DataGridView1_CellMouseEnter(ByVal sender As Object, _
            ByVal e As DataGridViewCellEventArgs) _ Handles DataGridView1.CellMouseEnter
      'ヘッダー以外のセル
        If e.ColumnIndex >= 0 And e.RowIndex >= 0 Then
            Dim dgv As DataGridView = CType(sender, DataGridView)
             'セルスタイルを変更する
            dgv(e.ColumnIndex, e.RowIndex).Style.BackColor = Color.Red
            dgv(e.ColumnIndex, e.RowIndex).Style.SelectionBackColor = Color.Red
        End If
    End Sub

    'DataGridView1のCellMouseLeaveイベントハンドラ
    Private Sub DataGridView1_CellMouseLeave(ByVal sender As Object, _
                ByVal e As DataGridViewCellEventArgs) _
                Handles DataGridView1.CellMouseLeave
        'ヘッダー以外のセル
        If e.ColumnIndex >= 0 And e.RowIndex >= 0 Then
                Dim dgv As DataGridView = CType(sender, DataGridView)
                'セルスタイルを元に戻す
                'セルスタイルを削除するなら、nullを設定してもよい
                dgv(e.ColumnIndex, e.RowIndex).Style.BackColor = Color.Empty
                dgv(e.ColumnIndex, e.RowIndex).Style.SelectionBackColor = Color.Empty
        End If
    End Sub

  

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值