DataGrid的使用方法

Me.DataGrid1.AllowSorting = Not Me.DataGrid1.AllowSorting '得到或设置一个值,它指示是否可通过单及列标头对网格进行排序

        Me.DataGrid1.AlternatingBackColor = Color.Yellow          '得到或设置网格中奇数行的背景色
        Me.DataGrid1.BackColor = Color.FromArgb(255, 0, 0)        '得到或设置网格中偶数行的背景色
        Me.DataGrid1.BackgroundColor = SystemColors.Desktop       '得到或设置网格中非行区域的颜色

        Me.DataGrid1.BackgroundImage = New Bitmap(Application.StartupPath & "/zengfanzhi.jpg")

        Me.DataGrid1.BorderStyle = BorderStyle.Fixed3D            '得到或设置网格中边框的样式

 

        '得到或设置标题区域...
        Me.DataGrid1.CaptionText = "ZengFanzhi"
        Me.DataGrid1.CaptionBackColor = Color.Black
        Me.DataGrid1.CaptionForeColor = Color.White
        Me.DataGrid1.CaptionFont = New Font("楷体", 13, FontStyle.Italic)
        Me.DataGrid1.CaptionVisible = True


        Me.DataGrid1.ColumnHeadersVisible = Not Me.DataGrid1.ColumnHeadersVisible '得到或设置列标题是否可见
        Me.DataGrid1.RowHeadersVisible = Not Me.DataGrid1.RowHeadersVisible

        '得到或设置具有焦点的单元格
        '当前行和列 ,行和列从索引从0开始 (Cell 单元)
        MsgBox(Me.DataGrid1.CurrentCell.RowNumber & Space(3) & Me.DataGrid1.CurrentCell.ColumnNumber)

        '得到或设置 选定行的索引
        MsgBox(Me.DataGrid1.CurrentRowIndex)

        Me.DataGrid1.Collapse(-1)  '折叠对于所有行存在的子关系或折叠指定行的子关系。
        Me.DataGrid1.Expand(-1)    '显示所有行或特定行的子关系(如果存在)
        '                           Expand vt.使膨胀,详述,扩张    vi.张开,发展

        Debug.WriteLine(Me.DataGrid1.IsExpanded(3))   '获得一个值,该值指示指定行的节点是展开的还是折叠的
        '-------------------------------------------------------------------------------------
        '数据绑定
        'Me.DataGrid1.DataBindings("CaptionText") +?

        '指示要在 DataGrid 显示的 DataSource 列表   ; Member 成员
        'me.DataGrid1.DataMember ?

        '获取控件的。。。
        Debug.WriteLine("DataGrid1.DefaultBackColor :" & Me.DataGrid1.DefaultBackColor().ToString)
        Debug.WriteLine("DataGrid1.DefaultFont      :" & Me.DataGrid1.DefaultFont.ToString)
        Debug.WriteLine("DataGrid1.DefaultForeColor :" & Me.DataGrid1.DefaultForeColor.ToString)
        'DataGrid1.DefaultBackColor :Color [Control]
        'DataGrid1.DefaultFont      :[Font: Name=宋体, Size=9, Units=3, GdiCharSet=134, GdiVerticalFont=False]
        'DataGrid1.DefaultForeColor :Color [ControlText]

        '试图将网格置于允许编辑的状态。
        'Me.DataGrid1.BeginEdit()

        Me.Text = Me.DataGrid1.FindForm().ToString   '检索控件所在的窗口

        MsgBox(Me.DataGrid1.FirstVisibleColumn) '获取网格中第一个可见列的索引
        Me.DataGrid1.FlatMode = True            '得到或设置一个值,该值指示网格是否以平面模式显示

        Me.DataGrid1.Font = New Font("楷体", 10, FontStyle.Bold)
        Me.DataGrid1.ForeColor = Color.Red

        '获取由行号和列号指定的单元格的Rectangle.
        Dim R As Rectangle = Me.DataGrid1.GetCellBounds(3, 1)
        Debug.WriteLine(R)

        '获取由当前单元格的Rectangle.
        Debug.WriteLine(Me.DataGrid1.GetCurrentCellBounds)

        Me.DataGrid1.GridLineColor = Color.Blue                '得到或设置网格线的颜色
        Me.DataGrid1.GridLineStyle() = DataGridLineStyle.None  '得到或设置网格的线型

        '得到或设置所有行标头和列标头的。。。
        Me.DataGrid1.HeaderBackColor = Color.Green
        Me.DataGrid1.HeaderFont = New Font("楷体", 13, FontStyle.Regular)
        Me.DataGrid1.HeaderForeColor = Color.Red

        Me.DataGrid1.SelectionBackColor = Color.Red
        Me.DataGrid1.SelectionForeColor = Color.Black

        '--------------------------------------------------------------------------------------

        'Me.DataGrid1.ReadOnly = True            '指示是否可以编辑,增加或删除网格中的行
        'Me.DataGrid1.ImeMode = ImeMode.Off      '获得或设置控件的输入法编辑器模式

        'Debug.WriteLine(Me.DataGrid1.IsExpanded(1)) '获得一个值,该值指示指定行的节点是展开的还是折叠的
        'Debug.WriteLine(Me.DataGrid1.IsSelected(3)) '获得一个值,该值指示指定行是否被选定

        'Me.DataGrid1.Item(3, 1) = 333 '获得或设置位于指定行和列的单元格的值

        '获取一个值,该值指示哪一个修改键(SHIFT、CTRL 和 ALT)处于按下的状态。
        'If the CTRL key is pressed when the control is clicked, hide the control.
        'If Control.ModifierKeys = Keys.Control Then CType(sender, Control).Hide()
        'Debug.WriteLine(Me.DataGrid1.ModifierKeys)

        ''指定定义哪个鼠标按钮曾按下的常数。
        'If Me.DataGrid1.MouseButtons = MouseButtons.Right Then
        '    MsgBox("You are pressed the MouseButtons.Right")
        'End If

        ''获得鼠标光标的位置(以屏幕坐标表示)
        'Me.Text = Me.DataGrid1.MousePosition.ToString

        'Me.Text = Me.DataGrid1.PointToScreen(New Point(0, 0)).ToString    '将指定工作区点的位置计算成屏幕坐标。
        'Me.Text = Me.DataGrid1.PointToClient(New Point(30, 30)).ToString  '将指定屏幕点的位置计算成工作区坐标

        'Me.DataGrid1.RectangleToClient() '计算指定屏幕矩形的大小和位置  (以工作区坐标表示)。
        'Me.DataGrid1.RectangleToScreen() '计算指定工作区矩形的大小和位置(以屏幕坐标表示  )。

        'Debug.WriteLine(Me.DataGrid1.IsSelected(3) = True)
        'Me.DataGrid1.Select(3)   '选择指定行
        'Me.DataGrid1.UnSelect(3) '取消指定行的选定


        'Me.DataGrid1.Update()    '使控件重绘其工作区的无效区域

        Debug.WriteLine("Me.DataGrid1.FirstVisibleColumn : " & Me.DataGrid1.FirstVisibleColumn())
        Debug.WriteLine("Me.DataGrid1.VisibleColumnCount : " & Me.DataGrid1.VisibleColumnCount) '获取可见列的数目")
        Debug.WriteLine("Me.DataGrid1.VisibleRowCount    : " & Me.DataGrid1.VisibleRowCount)

        '--------------------------------------------------------------------------------------------------
        '请在重置 DataSource 属性和 DataMember 属性(不管是单独设置还是通过 SetDataBinding 方法设置)之前设
        '置该属性,否则该属性无效。

        Dim RowH As Integer = Val(InputBox("Please input the RowHeigth : "))
        Dim ColW As Integer = Val(InputBox("Please input the ColWidth  : "))

        Me.DataGrid1.PreferredRowHeight() = RowH   '获取或设置控件的首选行高。
        Me.DataGrid1.PreferredColumnWidth() = ColW '获取或设置网格列的默认宽度(以像素为单位)。

        Me.DataGrid1.RowHeaderWidth() = 100        '获取或设置行标头宽度。
        '--------------------------------------------------------------------------------------------------
        '重置控件的。。。
        Me.DataGrid1.ResetAlternatingBackColor()

        Me.DataGrid1.ResetBackColor()
        Me.DataGrid1.ResetForeColor()
        Me.DataGrid1.ResetGridLineColor()
        Me.DataGrid1.ResetHeaderBackColor()
        Me.DataGrid1.ResetHeaderFont()
        Me.DataGrid1.ResetHeaderForeColor()

        Me.DataGrid1.ResetLinkColor()
        Me.DataGrid1.ResetLinkHoverColor()
        Me.DataGrid1.ResetSelectionBackColor()
        Me.DataGrid1.ResetSelectionForeColor()
        Me.DataGrid1.ResetText()

        '-----------------------------------------------------------------------------
        Me.DataGrid1.ReadOnly = True 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值