BriskDataGrid类参考
该类是一个自定义空间,继承自System.Windows.Forms.UserControl类。该类能够在运行时以二维表格的形式显示数据,并可以利用该控件修改数据。该控件明确限定只能绑定到DataView。还可以向该控件加入丰富的列样式,是最终用户在进行数据编辑的时候更加易用。
属性
注意:从System.Windows.Forms.UserControl类继承的属性一概省略。
和布局有关的属性
PreferredColumnWidth——指定网格的默认列宽。
PreferedRowHeight——指示首选的行高。
RowHeaderWidth——指示行标头的宽度。
和显示有关的属性
CaptionVisible——指示顶部标题是否可见。
ColumnHeadersVisible——指示列标头是否可见。
ParentRowsLableStyle——指示父行是否显示表和列的样式。
ParentRowsVisible——指示父行区域是否可见。
RowHeadersVisible——指示父行标头是否可见。
和行为有关的属性
AllowNavigation——指定要显示的链接以及链接显示时所在的上下文。
AllowSorting——指定是否可以通过单击列标头对网格进行重新排序。
和颜色有关的属性
AlternatingBackColor——获取或设置网格中奇数行的背景色。
BackColor——获取或设置网格中偶数行的背景色。
BackgroundColor——获取或设置网格中非行区域的颜色。
CaptionBackColor——获取或设置标题区域的背景色。
CaptionForeColor——获取或设置标题区域的前景色。
ForeColor——获取或设置前景色。
GridLineColor——获取或设置网格线颜色。
HeaderBackColor——获取或设置所有行标头和列标头的背景色。
HeaderForeColor——获取或设置所有标头的前景色。
LinkColor——获取或设置单击即可定位到子表的文本的颜色。
ParentRowsBackColor——获取或设置父行的背景色。
ParentRowsForeColor——获取或设置父行的前景色。
SelectionBackColor——获取或设置选定行的背景色。
SelectionForeColor——获取或设置选定行的前景色。
方法
注意:从System.Windows.Forms.UserControl类继承的方法一概省略。
BeginTableStyle()——开始设置BriskDataGrid的TableStyle。该方法必须和EndTableStyle()方法配合使用。
EndTableStyle()——结束设置BriskDataGrid的TableStyle。该方法必须和BeginTableStyle()方法配合使用。
AddCheckBoxColumn()——添加CheckBox列到BriskDataGrid的TableStyle。
AddDateTimePickerColumn()——添加DateTimePicker列到BriskDataGrid的TableStyle。
AddTextColumn()——添加Text列到BriskDataGrid的TableStyle。
AddSexBoxColumn()——添加SexBox列到BriskDataGrid的TableStyle。
AddComboBoxColumn()——添加ComboBox列到BriskDataGrid的TableStyle。
源码参考:
Imports System.ComponentModel
Public Class BriskDataGrid
Inherits System.Windows.Forms.UserControl
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
Me.Initialize()
End Sub
'UserControl1 重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Protected WithEvents DataGrid As System.Windows.Forms.DataGrid
Friend Shadows WithEvents ContextMenu As System.Windows.Forms.ContextMenu
Friend WithEvents miColumns As System.Windows.Forms.MenuItem
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.DataGrid = New System.Windows.Forms.DataGrid
Me.ContextMenu = New System.Windows.Forms.ContextMenu
Me.miColumns = New System.Windows.Forms.MenuItem
CType(Me.DataGrid, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'DataGrid
'
Me.DataGrid.AllowNavigation = False
Me.DataGrid.AllowSorting = False
Me.DataGrid.AlternatingBackColor = System.Drawing.Color.LightSeaGreen
Me.DataGrid.BackColor = System.Drawing.Color.OldLace
Me.DataGrid.BackgroundColor = System.Drawing.Color.DarkGray
Me.DataGrid.BorderStyle = System.Windows.Forms.BorderStyle.None
Me.DataGrid.CaptionVisible = False
Me.DataGrid.DataMember = ""
Me.DataGrid.Dock = System.Windows.Forms.DockStyle.Fill
Me.DataGrid.FlatMode = True
Me.DataGrid.GridLineColor = System.Drawing.Color.PaleTurquoise
Me.DataGrid.HeaderBackColor = System.Drawing.Color.Silver
Me.DataGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid.Location = New System.Drawing.Point(0, 0)
Me.DataGrid.Name = "DataGrid"
Me.DataGrid.PreferredRowHeight = 20
Me.DataGrid.ReadOnly = True
Me.DataGrid.RowHeaderWidth = 15
Me.DataGrid.SelectionBackColor = System.Drawing.Color.DarkSeaGreen
Me.DataGrid.SelectionForeColor = System.Drawing.Color.IndianRed
Me.DataGrid.Size = New System.Drawing.Size(150, 50)
Me.DataGrid.TabIndex = 0
'
'ContextMenu
'
Me.ContextMenu.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.miColumns})
'
'miColumns
'
Me.miColumns.Index = 0
Me.miColumns.Text = "列"
'
'BriskDataGrid
'
Me.Controls.Add(Me.DataGrid)
Me.Name = "BriskDataGrid"
Me.Size = New System.Drawing.Size(150, 50)
CType(Me.DataGrid, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Protected Sub Initialize()
Me.DataGrid.AllowSorting = False
Me.DataGrid.AllowNavigation = False
Me.DataGrid.ReadOnly = True
End Sub
'绑定数据网格
Public Sub SetDataBinding(ByVal dataView As DataView)
If dataView Is Nothing Then
Throw New NullReferenceException("方法的参数dataView不能为空。")
ElseIf dataView.Table Is Nothing Then
Throw New NullReferenceException("方法的参数dataView的属性Table不能为空。应该将一个DataTable对象赋值给它。")
End If
Me.DataGrid.SetDataBinding(dataView, "")
End Sub
'数据网格表样式
Private TableStyle As DataGridTableStyle
#Region "为数据网格添加表样式和列样式"
'''''''''''''''''''''''''''''''''''''''''''''''''''''
'开始设置DataGrid的TableStyle
'和EndTableStyl配合使用
Public Sub BeginTableStyle(ByVal MappingName As String)
'new一个TableStyle
Me.TableStyle = New DataGridTableStyle
'把DataGrid的属性给TableStyle
'允许索引
Me.TableStyle.AllowSorting = Me.DataGrid.AllowSorting
'设置网格中奇数行的背景色
Me.TableStyle.AlternatingBackColor = Me.DataGrid.AlternatingBackColor
'设置网格中偶数行的背景色
Me.TableStyle.BackColor = Me.DataGrid.BackColor
'指示列标头是否可见
Me.TableStyle.ColumnHeadersVisible = Me.DataGrid.ColumnHeadersVisible
'设置所绘制表的DataGrid控件
Me.TableStyle.DataGrid = Me.DataGrid
'设置网格表的前景色
Me.TableStyle.ForeColor = Me.DataGrid.ForeColor
'获取或设置网格线的颜色
Me.TableStyle.GridLineColor = Me.DataGrid.GridLineColor
'获取所绘制的该表中列的集合
Me.TableStyle.GridLineStyle = Me.DataGrid.GridLineStyle
'设置标头的背景色
Me.TableStyle.HeaderBackColor = Me.DataGrid.HeaderBackColor
'设置用于标头的标题的字体
Me.TableStyle.HeaderFont = Me.DataGrid.HeaderFont
'设置标头的前景色
Me.TableStyle.HeaderForeColor = Me.DataGrid.HeaderForeColor
'设置链接文本的颜色
Me.TableStyle.LinkColor = Me.DataGrid.LinkColor
'设置在显示新网格时创建列所用的宽度
Me.TableStyle.PreferredColumnWidth = Me.DataGrid.PreferredColumnWidth
'设置在显示新网格时创建行所用的高度
Me.TableStyle.PreferredRowHeight = Me.DataGrid.PreferredRowHeight
'指示是否可以编辑列
Me.TableStyle.ReadOnly = Me.DataGrid.ReadOnly
'指示行标头是否可见
Me.TableStyle.RowHeadersVisible = Me.DataGrid.RowHeadersVisible
'设置行标头宽度
Me.TableStyle.RowHeaderWidth = Me.DataGrid.RowHeaderWidth
'设置选定单元格的背景色
Me.TableStyle.SelectionBackColor = Me.DataGrid.SelectionBackColor
'设置选定单元格的前景色
Me.TableStyle.SelectionForeColor = Me.DataGrid.SelectionForeColor
'映射名
Me.TableStyle.MappingName = MappingName
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''
'结束设置DataGrid的TableStyle
'和BeginTableStyle配合使用
Public Sub EndTableStyle()
If Me.TableStyle Is Nothing Then
Throw New Exception("在调用方法EndTableStyle()之前必须先调用BeginTableStyle()方法。因为这两个方法必须协同工作。")
End If
Me.DataGrid.TableStyles.Add(TableStyle)
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'添加DataGridCheckBoxColumn到数据网格
'调用这个方法之前须调用BeginTableStyle方法
'调用这个方法之前须调用EndTableStyle方法
Public Sub AddCheckBoxColumn( _
ByVal CheckBoxColumn As DataGridCheckBoxColumn, _
ByVal MappingName As String, _
Optional ByVal HeaderText As String = "", _
Optional ByVal [ReadOnly] As Boolean = False, _
Optional ByVal Width As Integer = 75, _
Optional ByVal AllowNull As Boolean = False, _
Optional ByVal TrueValue As Object = True, _
Optional ByVal FalseValue As Object = False)
If Me.TableStyle Is Nothing Then
Throw New Exception("在调用方法AddCheckBoxColumn()之前必须先调用BeginTableStyle()方法。因为这两个方法必须协同工作。")
End If
If CheckBoxColumn Is Nothing Then
CheckBoxColumn = New DataGridCheckBoxColumn
End If
'MappingName
CheckBoxColumn.MappingName = MappingName
'HeaderText
If HeaderText.Length > 0 Then
CheckBoxColumn.HeaderText = HeaderText
Else
CheckBoxColumn.HeaderText = MappingName
End If
'ReadOnly
CheckBoxColumn.ReadOnly = [ReadOnly]
'列宽
CheckBoxColumn.Width = Width
'允许NULL
CheckBoxColumn.AllowNull = AllowNull
'TrueValue
CheckBoxColumn.TrueValue = TrueValue
'FalseValue
CheckBoxColumn.FalseValue = FalseValue
'把TextBoxColumn添加到GridColumnStyles
Me.TableStyle.GridColumnStyles.Add(CheckBoxColumn)
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'添加DataGridDateTimePickerColumn到数据网格
'调用这个方法之前须调用BeginTableStyle方法
'调用这个方法之前须调用EndTableStyle方法
Public Sub AddDateTimePickerColumn( _
ByVal DateTimePickerColumn As DataGridDateTimePickerColumn, _
ByVal MappingName As String, _
Optional ByVal HeaderText As String = "", _
Optional ByVal [ReadOnly] As Boolean = False, _
Optional ByVal Alignment As HorizontalAlignment = HorizontalAlignment.Center, _
Optional ByVal NullText As String = "", _
Optional ByVal Width As Integer = 200, _
Optional ByVal Format As String = "yyyy年MM月dd日 HH时mm分ss秒")
If Me.TableStyle Is Nothing Then
Throw New Exception("在调用方法AddDateTimePickerColumn()之前必须先调用BeginTableStyle()方法。因为这两个方法必须协同工作。")
End If
If DateTimePickerColumn Is Nothing Then
DateTimePickerColumn = New DataGridDateTimePickerColumn
End If
'映射名称(数据表里面的列名)
DateTimePickerColumn.MappingName = MappingName
'如果传送了列标题文本
If HeaderText.Length > 0 Then
'把传递过来的列标题文本给picker
DateTimePickerColumn.HeaderText = HeaderText
Else
'否则把MappingName当作列标题
DateTimePickerColumn.HeaderText = MappingName
End If
'只读
DateTimePickerColumn.ReadOnly = [ReadOnly]
'对齐方式
DateTimePickerColumn.Alignment = Alignment
'null text
DateTimePickerColumn.NullText = NullText
'宽度
DateTimePickerColumn.Width = Width
'日期时间的格式
DateTimePickerColumn.Format = Format
Try
'把列加入数据网格的里面去
Me.TableStyle.GridColumnStyles.Add(DateTimePickerColumn)
Catch ex As Exception
System.Diagnostics.Debug.WriteLine("错误:把DateTimePicker列加入数据网格的里面去的时候出错")
Throw ex
End Try
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'添加DataGridTextColumn
'调用这个方法之前须调用BeginTableStyle方法
'调用这个方法之前须调用EndTableStyle方法
Public Sub AddTextColumn( _
ByVal TextColumn As DataGridTextColumn, _
ByVal MappingName As String, _
Optional ByVal HeaderText As String = "", _
Optional ByVal [ReadOnly] As Boolean = False, _
Optional ByVal Alignment As HorizontalAlignment = HorizontalAlignment.Center, _
Optional ByVal NullText As String = "", _
Optional ByVal Width As Integer = 75)
If Me.TableStyle Is Nothing Then
Throw New Exception("在调用方法AddTextColumn()之前必须先调用BeginTableStyle()方法。因为这两个方法必须协同工作。")
End If
If TextColumn Is Nothing Then
TextColumn = New DataGridTextColumn
End If
'mapping name
TextColumn.MappingName = MappingName
'header text
If HeaderText.Length > 0 Then
TextColumn.HeaderText = HeaderText
Else
TextColumn.HeaderText = MappingName
End If
'read only
TextColumn.ReadOnly = [ReadOnly]
'对齐方式
TextColumn.Alignment = Alignment
'null text
TextColumn.NullText = NullText
'width
TextColumn.Width = Width
Try
Me.TableStyle.GridColumnStyles.Add(TextColumn)
Catch ex As Exception
System.Diagnostics.Debug.WriteLine("错误:把Text列加入数据网格的里面去的时候出错")
Throw ex
End Try
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'添加DataGridSexBoxColumn到数据网格里
'调用这个方法之前须调用BeginTableStyle方法
'调用这个方法之前须调用EndTableStyle方法
Public Sub AddSexBoxColumn( _
ByVal SexBoxColumn As DataGridSexBoxColumn, _
ByVal MappingName As String, _
Optional ByVal HeaderText As String = "", _
Optional ByVal [ReadOnly] As Boolean = False, _
Optional ByVal Alignment As HorizontalAlignment = HorizontalAlignment.Center, _
Optional ByVal NullText As String = "", _
Optional ByVal Width As Integer = 75)
If Me.TableStyle Is Nothing Then
Throw New Exception("在调用方法AddSexBoxColumn()之前必须先调用BeginTableStyle()方法。因为这两个方法必须协同工作。")
End If
If SexBoxColumn Is Nothing Then
SexBoxColumn = New DataGridSexBoxColumn
End If
'mapping name
SexBoxColumn.MappingName = MappingName
'header text
If HeaderText.Length > 0 Then
SexBoxColumn.HeaderText = HeaderText
Else
SexBoxColumn.HeaderText = MappingName
End If
'read only
SexBoxColumn.ReadOnly = [ReadOnly]
'对齐方式
SexBoxColumn.Alignment = Alignment
'null text
SexBoxColumn.NullText = NullText
'列宽
SexBoxColumn.Width = Width
Try
Me.TableStyle.GridColumnStyles.Add(SexBoxColumn)
Catch ex As Exception
System.Diagnostics.Debug.WriteLine("错误:把SexBoxt列加入数据网格的里面去的时候出错")
Throw ex
End Try
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'添加DataGridComboBoxColumn到数据网格里
'调用这个方法之前须调用BeginTableStyle方法
'调用这个方法之前须调用EndTableStyle方法
Public Sub AddComboBoxColumn( _
ByVal ComboBoxColumn As DataGridComboBoxColumn, _
ByVal ParentTable As DataTable, _
ByVal ParentColumn As String, _
ByVal DisplayColumn As String, _
ByVal MappingName As String, _
Optional ByVal HeaderText As String = "", _
Optional ByVal [ReadOnly] As Boolean = False, _
Optional ByVal Alignment As HorizontalAlignment = HorizontalAlignment.Center, _
Optional ByVal NullText As String = "", _
Optional ByVal Width As Integer = 75)
If Me.TableStyle Is Nothing Then
Throw New Exception("在调用方法AddComboBoxColumn()之前必须先调用BeginTableStyle()方法。因为这两个方法必须协同工作。")
End If
If ComboBoxColumn Is Nothing Then
ComboBoxColumn = New DataGridComboBoxColumn
End If
ComboBoxColumn.ParentTable = ParentTable
ComboBoxColumn.ParentColumn = ParentColumn
ComboBoxColumn.DisplayColumn = DisplayColumn
ComboBoxColumn.MappingName = MappingName
If HeaderText.Length > 0 Then
ComboBoxColumn.HeaderText = HeaderText
Else
ComboBoxColumn.HeaderText = MappingName
End If
ComboBoxColumn.ReadOnly = [ReadOnly]
ComboBoxColumn.Alignment = Alignment
ComboBoxColumn.NullText = NullText
ComboBoxColumn.Width = Width
Try
Me.TableStyle.GridColumnStyles.Add(ComboBoxColumn)
Catch ex As Exception
System.Diagnostics.Debug.WriteLine("错误:把ComboBox列加入数据网格的里面去的时候出错")
Throw ex
End Try
End Sub
#End Region
Private Sub DataGrid_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid.MouseUp
If e.Button = MouseButtons.Left Then
'如果单击左键,而且击中的是列头就排序
Dim dg As DataGrid = sender
Dim hti As System.Windows.Forms.DataGrid.HitTestInfo
hti = dg.HitTest(e.X, e.Y)
If hti.Type = DataGrid.HitTestType.ColumnHeader AndAlso (Not (Me.TableStyle Is Nothing)) Then
Dim mappingName As String = Me.TableStyle.GridColumnStyles.Item(hti.Column()).MappingName()
'排序
Me.Sort(mappingName)
End If
ElseIf e.Button = MouseButtons.Right AndAlso (Not (Me.TableStyle Is Nothing)) Then
'如果是右键就弹出菜单
Me.ContextMenu.Show(Me, New Point(e.X, e.Y))
End If
End Sub
#Region "排序"
'排序
Protected Sub Sort(ByVal mappingName As String)
If Me.AllowSorting = True Then
Dim dv As DataView = Me.DataGrid.DataSource
If dv.Sort = mappingName Then
dv.Sort = mappingName & " DESC"
Else
dv.Sort = mappingName
End If
End If
End Sub
#End Region
#Region "选择那些列显示哪些列隐藏"
Private Sub miColumns_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miColumns.Click
Dim dlgColumns As New ColumnsDialog
If Me.TableStyle Is Nothing Then
Throw New Exception("没有为数据网格添加表样式。")
End If
'为ColumnsList添加item
For Each col As DataGridColumnStyle In Me.TableStyle.GridColumnStyles
Dim b As Boolean
If col.Width > 0 Then
b = True
Else
b = False
End If
dlgColumns.ColumnsList.Items.Add(col.HeaderText, b)
Next
'显示对话框
dlgColumns.ShowDialog()
'根据选择情况调整列是隐藏还是显示
Dim i As Integer = 0
For Each item As Object In dlgColumns.ColumnsList.Items
Dim r As Integer = dlgColumns.ColumnsList.CheckedItems.IndexOf(item)
If r = -1 Then '没有钩
Dim col As DataGridColumnStyle = Me.TableStyle.GridColumnStyles.Item(i)
col.Width = -1
Else '有钩
Dim col As DataGridColumnStyle = Me.TableStyle.GridColumnStyles.Item(i)
'但是原先是隐藏的
If col.Width < 0 Then
col.Width = 75
End If
End If
i = i + 1
Next
End Sub
#End Region
#Region "和布局有关的属性"
<Description("指定网格列的默认宽度。"), Category("布局")> _
Public Property ColumnWidth() As Integer
Get
Return Me.DataGrid.PreferredColumnWidth
End Get
Set(ByVal Value As Integer)
Me.DataGrid.PreferredColumnWidth = Value
End Set
End Property
<Description("指示首选行高。"), Category("布局")> _
Public Property PreferredRowHeight() As Integer
Get
Return Me.DataGrid.PreferredRowHeight
End Get
Set(ByVal Value As Integer)
Me.DataGrid.PreferredRowHeight = Value
End Set
End Property
<Description("指示行标头的宽度。"), Category("布局")> _
Public Property RowHeaderWidth() As Integer
Get
Return Me.DataGrid.RowHeaderWidth
End Get
Set(ByVal Value As Integer)
Me.DataGrid.RowHeaderWidth = Value
End Set
End Property
#End Region
#Region "和外观有关的属性"
<Description("指示DataGrid的边框样式。"), Category("外观")> _
Public Property BorderStyle() As BorderStyle
Get
Return Me.DataGrid.BorderStyle
End Get
Set(ByVal Value As BorderStyle)
Me.DataGrid.BorderStyle = Value
End Set
End Property
<Description("指示顶部标题的字体。"), Category("外观")> _
Public Property CaptionFont() As Font
Get
Return Me.DataGrid.CaptionFont
End Get
Set(ByVal Value As Font)
Me.DataGrid.CaptionFont = Value
End Set
End Property
<Description("指示顶部标题中所显示的文本。"), Category("外观")> _
Public Property CaptionText() As String
Get
Return Me.DataGrid.CaptionText
End Get
Set(ByVal Value As String)
Me.DataGrid.CaptionText = Value
End Set
End Property
<Description("指示网格外观是否为平面。"), Category("外观")> _
Public Property FlatMode() As Boolean
Get
Return Me.DataGrid.FlatMode
End Get
Set(ByVal Value As Boolean)
Me.DataGrid.FlatMode = Value
End Set
End Property
<Description("用于指示控件中文本的字体。"), Category("外观")> _
Public Shadows Property Font() As Font
Get
Return Me.DataGrid.Font
End Get
Set(ByVal Value As Font)
Me.DataGrid.Font = Value
End Set
End Property
<Description("指示网格线的样式。"), Category("外观")> _
Public Property GridLineStyle() As DataGridLineStyle
Get
Return Me.DataGrid.GridLineStyle
End Get
Set(ByVal Value As DataGridLineStyle)
Me.DataGrid.GridLineStyle = Value
End Set
End Property
<Description("指示列和行标头中文本的字体。"), Category("外观")> _
Public Property HeaderFont() As Font
Get
Return Me.DataGrid.HeaderFont
End Get
Set(ByVal Value As Font)
Me.DataGrid.HeaderFont = Value
End Set
End Property
#End Region
#Region "和显示有关的属性"
<Description("指示顶部标题是否是否可见。"), Category("显示")> _
Public Property CaptionVisible() As Boolean
Get
Return Me.DataGrid.CaptionVisible
End Get
Set(ByVal Value As Boolean)
Me.DataGrid.CaptionVisible = Value
End Set
End Property
<Description("指示列标头是否可见。"), Category("显示")> _
Public Property ColumnHeadersVisible() As Boolean
Get
Return Me.DataGrid.ColumnHeadersVisible
End Get
Set(ByVal Value As Boolean)
Me.DataGrid.ColumnHeadersVisible = Value
End Set
End Property
<Description("指示父行是否显示表和列的样式。"), Category("显示")> _
Public Property ParentRowsLableStyle() As DataGridParentRowsLabelStyle
Get
Return Me.DataGrid.ParentRowsLabelStyle
End Get
Set(ByVal Value As DataGridParentRowsLabelStyle)
Me.DataGrid.ParentRowsLabelStyle = Value
End Set
End Property
<Description("指示父行区域是否可见。"), Category("显示")> _
Public Property ParentRowsVisible() As Boolean
Get
Return Me.DataGrid.ParentRowsVisible
End Get
Set(ByVal Value As Boolean)
Me.DataGrid.ParentRowsVisible = Value
End Set
End Property
<Description("指示行标头是否可见。"), Category("显示")> _
Public Property RowHeadersVisible() As Boolean
Get
Return Me.DataGrid.RowHeadersVisible
End Get
Set(ByVal Value As Boolean)
Me.DataGrid.RowHeadersVisible = Value
End Set
End Property
#End Region
#Region "和行为有关的属性"
<Description("指定要显示的连接以及链接显示时所在的上下文。"), Category("行为")> _
Public Property AllowNavigation() As Boolean
Get
Return Me.DataGrid.AllowNavigation
End Get
Set(ByVal Value As Boolean)
Me.DataGrid.AllowNavigation = Value
End Set
End Property
Private _AllowSorting As Boolean = True
<Description("指示是否可以通过单击列标头对网格进行重新排序。"), Category("行为")> _
Public Property AllowSorting() As Boolean
Get
Return Me._AllowSorting
End Get
Set(ByVal Value As Boolean)
Me._AllowSorting = Value
End Set
End Property
#End Region
#Region "和颜色有关的属性"
'获取或设置网格中奇数行的背景色
<Description("获取或设置网格中基数行的背景色。"), Category("颜色")> _
Public Property AlternatingBackColor() As Color
Get
Return Me.DataGrid.AlternatingBackColor
End Get
Set(ByVal Value As Color)
Me.DataGrid.AlternatingBackColor = Value
End Set
End Property
'获取或设置网格中偶数行的背景色
<Description("获取或设置网格中偶数行的背景色。"), Category("颜色")> _
Public Overloads Property BackColor() As Color
Get
Return Me.DataGrid.BackColor
End Get
Set(ByVal Value As Color)
Me.DataGrid.BackColor = Value
End Set
End Property
'获取或设置网格中非行区域的颜色
<Description("获取或设置网格中非行区域的颜色。"), Category("颜色")> _
Public Property BackgroundColor() As Color
Get
Return Me.DataGrid.BackgroundColor
End Get
Set(ByVal Value As Color)
Me.DataGrid.BackgroundColor = Value
End Set
End Property
'获取或设置标题区域的背景色
<Description("获取或设置标题区域的背景色。"), Category("颜色")> _
Public Property CaptionBackColor() As Color
Get
Return Me.DataGrid.CaptionBackColor
End Get
Set(ByVal Value As Color)
Me.DataGrid.CaptionBackColor = Value
End Set
End Property
'获取或设置标题区域的前景色
<Description("获取或设置标题区域的前景色。"), Category("颜色")> _
Public Property CaptionForeColor() As Color
Get
Return Me.DataGrid.CaptionForeColor
End Get
Set(ByVal Value As Color)
Me.DataGrid.CaptionForeColor = Value
End Set
End Property
'获取或设置前景色(通常为文本的颜色)属性
<Description("获取或设置前景色(通常为文本的颜色)。"), Category("颜色")> _
Public Overloads Property ForeColor() As Color
Get
Return Me.DataGrid.ForeColor
End Get
Set(ByVal Value As Color)
Me.DataGrid.ForeColor = Value
End Set
End Property
'获取或设置网格线的颜色
<Description("获取或设置网格线的颜色。"), Category("颜色")> _
Public Overloads Property GridLineColor() As Color
Get
Return Me.DataGrid.GridLineColor
End Get
Set(ByVal Value As Color)
Me.DataGrid.GridLineColor = Value
End Set
End Property
'获取或设置所有行标头和列标头的背景色
<Description("获取或设置所有行标头和列标头的背景色。"), Category("颜色")> _
Public Property HeaderBackColor() As Color
Get
Return Me.DataGrid.HeaderBackColor
End Get
Set(ByVal Value As Color)
Me.DataGrid.HeaderBackColor = Value
End Set
End Property
'获取或设置标头的前景色
<Description("获取或设置标头的前景色。"), Category("颜色")> _
Public Property HeaderForeColor() As Color
Get
Return Me.DataGrid.HeaderForeColor
End Get
Set(ByVal Value As Color)
Me.DataGrid.HeaderForeColor = Value
End Set
End Property
'获取或设置单击即可定位到子表的文本的颜色
<Description("获取或设置单击即可定位到子表的文本的颜色。"), Category("颜色")> _
Public Property LinkColor() As Color
Get
Return Me.DataGrid.LinkColor
End Get
Set(ByVal Value As Color)
Me.DataGrid.LinkColor = Value
End Set
End Property
'获取或设置父行的背景色
<Description("获取或设置父行的背景色。"), Category("颜色")> _
Public Property ParentRowsBackColor() As Color
Get
Return Me.DataGrid.ParentRowsBackColor
End Get
Set(ByVal Value As Color)
Me.DataGrid.ParentRowsBackColor = Value
End Set
End Property
'获取或设置父行的前景色
<Description("获取或设置父行的前景色。"), Category("颜色")> _
Public Property ParentRowsForeColor() As Color
Get
Return Me.DataGrid.ParentRowsForeColor
End Get
Set(ByVal Value As Color)
Me.DataGrid.ParentRowsForeColor = Value
End Set
End Property
'获取或设置选定行的背景色
<Description("获取或设置选定行的背景色。"), Category("颜色")> _
Public Property SelectionBackColor() As Color
Get
Return Me.DataGrid.SelectionBackColor
End Get
Set(ByVal Value As Color)
Me.DataGrid.SelectionBackColor = Value
End Set
End Property
'获取或设置选定行的前景色
<Description("获取或设置选定行的前景色。"), Category("颜色")> _
Public Property SelectionForeColor() As Color
Get
Return Me.DataGrid.SelectionForeColor
End Get
Set(ByVal Value As Color)
Me.DataGrid.SelectionForeColor = Value
End Set
End Property
#End Region
End Class
Public Class ColumnsDialog
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents btnOK As System.Windows.Forms.Button
Public WithEvents ColumnsList As System.Windows.Forms.CheckedListBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.ColumnsList = New System.Windows.Forms.CheckedListBox
Me.btnOK = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'ColumnsList
'
Me.ColumnsList.BackColor = System.Drawing.Color.LightGray
Me.ColumnsList.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.ColumnsList.ForeColor = System.Drawing.Color.IndianRed
Me.ColumnsList.Location = New System.Drawing.Point(8, 8)
Me.ColumnsList.Name = "ColumnsList"
Me.ColumnsList.Size = New System.Drawing.Size(160, 146)
Me.ColumnsList.TabIndex = 0
'
'btnOK
'
Me.btnOK.BackColor = System.Drawing.Color.DarkSeaGreen
Me.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.btnOK.ForeColor = System.Drawing.Color.IndianRed
Me.btnOK.Location = New System.Drawing.Point(48, 160)
Me.btnOK.Name = "btnOK"
Me.btnOK.Size = New System.Drawing.Size(80, 23)
Me.btnOK.TabIndex = 1
Me.btnOK.Text = "决定"
'
'ColumnsDialog
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(176, 192)
Me.Controls.Add(Me.btnOK)
Me.Controls.Add(Me.ColumnsList)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "ColumnsDialog"
Me.Opacity = 0.9
Me.ShowInTaskbar = False
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
Me.Text = "选择要显示的列"
Me.TransparencyKey = System.Drawing.SystemColors.Control
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
Me.Close()
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Close()
End Sub
End Class