承载 ComboBox 控件的 DataGridColumnStyle (VB.NET)

重写ComboBox类
None.gif Imports  System.Windows.Forms
None.gif
ExpandedBlockStart.gifContractedBlock.gif
Public   Class AutoCompleteComboBox Class AutoCompleteComboBox
InBlock.gif    
Inherits ComboBox
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Sub New()Sub New()
InBlock.gif        
MyBase.New()
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
InBlock.gif    
Private mResetOnClear As Boolean = False
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Protected Overrides Sub RefreshItem()Sub RefreshItem(ByVal index As Integer)
InBlock.gif        
MyBase.RefreshItem(index)
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Protected Overrides Sub SetItemsCore()Sub SetItemsCore(ByVal items As System.Collections.IList)
InBlock.gif        
MyBase.SetItemsCore(items)
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Shadows Sub KeyPress()Sub KeyPress(ByVal sender As ObjectByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
InBlock.gif        
Dim intIndex As Integer
InBlock.gif        
Dim strEntry As String
InBlock.gif
InBlock.gif        
If Char.IsControl(e.KeyChar) Then
InBlock.gif            
If MyBase.SelectionStart <= 1 Then
InBlock.gif                
If mResetOnClear Then
InBlock.gif                    
MyBase.SelectedIndex = 0
InBlock.gif                    
MyBase.SelectAll()
InBlock.gif                
Else
InBlock.gif                    
MyBase.Text = String.Empty
InBlock.gif                    
MyBase.SelectedIndex = -1
InBlock.gif                
End If
InBlock.gif                e.Handled 
= True
InBlock.gif                
Exit Sub
InBlock.gif            
End If
InBlock.gif            
If MyBase.SelectionLength = 0 Then
InBlock.gif                strEntry 
= MyBase.Text.Substring(0MyBase.Text.Length - 1)
InBlock.gif            
Else
InBlock.gif                strEntry 
= MyBase.Text.Substring(0MyBase.SelectionStart - 1)
InBlock.gif            
End If
InBlock.gif        
ElseIf (Not Char.IsLetterOrDigit(e.KeyChar)) And (Not Char.IsWhiteSpace(e.KeyChar)) Then  '< 32 Or KeyAscii > 127 Then
InBlock.gif
            Exit Sub
InBlock.gif        
Else
InBlock.gif            
If MyBase.SelectionLength = 0 Then
InBlock.gif                strEntry 
= UCase(MyBase.Text & e.KeyChar)
InBlock.gif            
Else
InBlock.gif                strEntry 
= MyBase.Text.Substring(0MyBase.SelectionStart) & e.KeyChar
InBlock.gif            
End If
InBlock.gif        
End If
InBlock.gif
InBlock.gif        
MyBase.DroppedDown = Char.IsLetterOrDigit(e.KeyChar)
InBlock.gif
InBlock.gif        intIndex 
= MyBase.FindString(strEntry)
InBlock.gif        
If intIndex <> -1 Then
InBlock.gif            
MyBase.SelectedIndex = intIndex
InBlock.gif            
MyBase.SelectionStart = strEntry.Length
InBlock.gif            
MyBase.SelectionLength = MyBase.Text.Length - MyBase.SelectionStart
InBlock.gif        
End If
InBlock.gif
InBlock.gif        e.Handled 
= True
InBlock.gif        
Exit Sub
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Property ResetOnClear()Property ResetOnClear() As Boolean
InBlock.gif        
Get
InBlock.gif            
Return mResetOnClear
InBlock.gif        
End Get
InBlock.gif        
Set(ByVal Value As Boolean)
InBlock.gif            mResetOnClear 
= Value
InBlock.gif        
End Set
ExpandedSubBlockEnd.gif    
End Property

ExpandedBlockEnd.gif
End Class

None.gif
实现类
None.gif Option   Strict   On
None.gif
Option   Explicit   On  
None.gif
Imports  System.Collections
None.gif
Imports  System.ComponentModel
None.gif
Imports  System.Drawing
None.gif
Imports  System.Windows.Forms
None.gif
Imports  System.Data
None.gif
ExpandedBlockStart.gifContractedBlock.gif
Public   Class DataGridComboBox Class DataGridComboBox
InBlock.gif    
Inherits AutoCompleteComboBox
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Sub New()Sub New()
InBlock.gif        
MyBase.New()
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif    
Public isInEditOrNavigateMode As Boolean = True
InBlock.gif
ExpandedBlockEnd.gif
End Class

None.gif
ExpandedBlockStart.gifContractedBlock.gif
Public   Class DataGridComboBoxColumnStyle Class DataGridComboBoxColumnStyle
InBlock.gif    
Inherits DataGridColumnStyle
InBlock.gif
InBlock.gif    
Private xMargin As Integer = 2
InBlock.gif    
Private yMargin As Integer = 1
InBlock.gif    
Private Combo As DataGridComboBox
InBlock.gif    
Private _DisplayMember As String
InBlock.gif    
Private _ValueMember As String
InBlock.gif
InBlock.gif    
Private OldVal As String = String.Empty
InBlock.gif    
Private InEdit As Boolean = False
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Sub New()Sub New(ByRef DataSource As DataTable, _
InBlock.gif                   
ByVal DisplayMember As Integer, _
InBlock.gif                   
ByVal ValueMember As Integer)
InBlock.gif
InBlock.gif        Combo 
= New DataGridComboBox
InBlock.gif        _DisplayMember 
= DataSource.Columns.Item(index:=DisplayMember).ToString
InBlock.gif        _ValueMember 
= DataSource.Columns.Item(index:=ValueMember).ToString
InBlock.gif
InBlock.gif        
With Combo
InBlock.gif            .Visible 
= False
InBlock.gif            .DataSource 
= DataSource
InBlock.gif            .DisplayMember 
= _DisplayMember
InBlock.gif            .ValueMember 
= _ValueMember
InBlock.gif        
End With
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Sub New()Sub New(ByRef DataSource As DataTable, _
InBlock.gif                   
ByVal DisplayMember As String, _
InBlock.gif                   
ByVal ValueMember As String)
InBlock.gif
InBlock.gif        Combo 
= New DataGridComboBox
InBlock.gif        
With Combo
InBlock.gif            .Visible 
= False
InBlock.gif            .DataSource 
= DataSource
InBlock.gif            .DisplayMember 
= DisplayMember
InBlock.gif            .ValueMember 
= ValueMember
InBlock.gif        
End With
InBlock.gif
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Protected Overloads Overrides Sub Abort()Sub Abort(ByVal RowNum As Integer)
InBlock.gif        Debug.WriteLine(
"Abort()")
InBlock.gif        RollBack()
InBlock.gif        HideComboBox()
InBlock.gif        EndEdit()
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Protected Overloads Overrides Function Commit()Function Commit(ByVal DataSource As CurrencyManager, _
InBlock.gif                                                  
ByVal RowNum As IntegerAs Boolean
InBlock.gif        HideComboBox()
InBlock.gif        
If Not InEdit Then
InBlock.gif            
Return True
InBlock.gif        
End If
InBlock.gif
InBlock.gif        
Try
InBlock.gif            
Dim Value As Object = Combo.SelectedValue
InBlock.gif            
If NullText.Equals(Value) Then
InBlock.gif                Value 
= Convert.DBNull
InBlock.gif            
End If
InBlock.gif            SetColumnValueAtRow(DataSource, RowNum, Value)
InBlock.gif        
Catch e As Exception
InBlock.gif            RollBack()
InBlock.gif            
Return False
InBlock.gif        
End Try
InBlock.gif        EndEdit()
InBlock.gif        
Return True
ExpandedSubBlockEnd.gif    
End Function

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Protected Overloads Overrides Sub ConcedeFocus()Sub ConcedeFocus()
InBlock.gif        Combo.Visible 
= False
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Protected Overloads Overrides Sub Edit()Sub Edit(ByVal Source As CurrencyManager, _
InBlock.gif                                           
ByVal Rownum As Integer, _
InBlock.gif                                           
ByVal Bounds As Rectangle, _
InBlock.gif                                           
ByVal [ReadOnlyAs Boolean, _
InBlock.gif                                           
ByVal InstantText As String, _
InBlock.gif                                           
ByVal CellIsVisible As Boolean)
InBlock.gif
InBlock.gif        Combo.Text 
= String.Empty
InBlock.gif
InBlock.gif        
Dim OriginalBounds As Rectangle = Bounds
InBlock.gif
InBlock.gif        OldVal 
= Combo.Text
InBlock.gif
InBlock.gif        
If CellIsVisible Then
InBlock.gif            Bounds.Offset(xMargin, yMargin)
InBlock.gif            Bounds.Width 
-= xMargin * 2
InBlock.gif            Bounds.Height 
-= yMargin
InBlock.gif            Combo.Bounds 
= Bounds
InBlock.gif            Combo.Visible 
= True
InBlock.gif        
Else
InBlock.gif            Combo.Bounds 
= OriginalBounds
InBlock.gif            Combo.Visible 
= False
InBlock.gif        
End If
InBlock.gif
InBlock.gif        Combo.SelectedValue 
= GetText(GetColumnValueAtRow(Source, Rownum))
InBlock.gif
InBlock.gif        
If Not InstantText Is Nothing Then
InBlock.gif            Combo.SelectedValue 
= InstantText
InBlock.gif        
End If
InBlock.gif
InBlock.gif        Combo.RightToLeft 
= Me.DataGridTableStyle.DataGrid.RightToLeft
InBlock.gif        Combo.Focus()
InBlock.gif
InBlock.gif        
If InstantText Is Nothing Then
InBlock.gif            Combo.SelectAll()
InBlock.gif        
Else
InBlock.gif            
Dim [EndAs Integer = Combo.Text.Length
InBlock.gif            Combo.Select([
End], 0)
InBlock.gif        
End If
InBlock.gif
InBlock.gif        
If Combo.Visible Then
InBlock.gif            DataGridTableStyle.DataGrid.Invalidate(OriginalBounds)
InBlock.gif        
End If
InBlock.gif
InBlock.gif        InEdit 
= True
InBlock.gif
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Protected Overloads Overrides Function GetMinimumHeight()Function GetMinimumHeight() As Integer
InBlock.gif        
Return Combo.PreferredHeight + yMargin
ExpandedSubBlockEnd.gif    
End Function

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Protected Overloads Overrides Function GetPreferredHeight()Function GetPreferredHeight(ByVal g As Graphics, _
InBlock.gif                                                              
ByVal Value As ObjectAs Integer
InBlock.gif        Debug.WriteLine(
"GetPreferredHeight()")
InBlock.gif        
Dim NewLineIndex As Integer = 0
InBlock.gif        
Dim NewLines As Integer = 0
InBlock.gif        
Dim ValueString As String = Me.GetText(Value)
InBlock.gif        
Do
InBlock.gif            
While NewLineIndex <> -1
InBlock.gif                NewLineIndex 
= ValueString.IndexOf("r\n", NewLineIndex + 1)
InBlock.gif                NewLines 
+= 1
InBlock.gif            
End While
InBlock.gif        
Loop
InBlock.gif
InBlock.gif        
Return FontHeight * NewLines + yMargin
ExpandedSubBlockEnd.gif    
End Function

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Protected Overloads Overrides Function GetPreferredSize()Function GetPreferredSize(ByVal g As Graphics, _
InBlock.gif                                                            
ByVal Value As ObjectAs Size
InBlock.gif        
Dim Extents As Size = Size.Ceiling(g.MeasureString(GetText(Value), _
InBlock.gif                                           
Me.DataGridTableStyle.DataGrid.Font))
InBlock.gif        Extents.Width 
+= xMargin * 2 + DataGridTableGridLineWidth
InBlock.gif        Extents.Height 
+= yMargin
InBlock.gif        
Return Extents
ExpandedSubBlockEnd.gif    
End Function

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Protected Overloads Overrides Sub Paint()Sub Paint(ByVal g As Graphics, _
InBlock.gif                                            
ByVal Bounds As Rectangle, _
InBlock.gif                                            
ByVal Source As CurrencyManager, _
InBlock.gif                                            
ByVal RowNum As Integer)
InBlock.gif        Paint(g, Bounds, Source, RowNum, 
False)
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Protected Overloads Overrides Sub Paint()Sub Paint(ByVal g As Graphics, _
InBlock.gif                                            
ByVal Bounds As Rectangle, _
InBlock.gif                                            
ByVal Source As CurrencyManager, _
InBlock.gif                                            
ByVal RowNum As Integer, _
InBlock.gif                                            
ByVal AlignToRight As Boolean)
InBlock.gif        
Dim Text As String = GetText(GetColumnValueAtRow(Source, RowNum))
InBlock.gif        PaintText(g, Bounds, Text, AlignToRight)
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Protected Overloads Sub Paint()Sub Paint(ByVal g As Graphics, _
InBlock.gif                                  
ByVal Bounds As Rectangle, _
InBlock.gif                                  
ByVal Source As CurrencyManager, _
InBlock.gif                                  
ByVal RowNum As Integer, _
InBlock.gif                                  
ByVal BackBrush As Brush, _
InBlock.gif                                  
ByVal ForeBrush As Brush, _
InBlock.gif                                  
ByVal AlignToRight As Boolean)
InBlock.gif
InBlock.gif        
Dim Text As String = GetText(GetColumnValueAtRow(Source, RowNum))
InBlock.gif        PaintText(g, Bounds, Text, BackBrush, ForeBrush, AlignToRight)
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Protected Overloads Overrides Sub SetDataGridInColumn()Sub SetDataGridInColumn(ByVal Value As DataGrid)
InBlock.gif        
MyBase.SetDataGridInColumn(Value)
InBlock.gif        
If Not (Combo.Parent Is Value) Then
InBlock.gif            
If Not (Combo.Parent Is NothingThen
InBlock.gif                Combo.Parent.Controls.Remove(Combo)
InBlock.gif            
End If
InBlock.gif        
End If
InBlock.gif
InBlock.gif        
If Not (Value Is NothingThen Value.Controls.Add(Combo)
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Protected Overloads Overrides Sub UpdateUI()Sub UpdateUI(ByVal Source As CurrencyManager, _
InBlock.gif                                               
ByVal RowNum As IntegerByVal InstantText As String)
InBlock.gif        Combo.Text 
= GetText(GetColumnValueAtRow(Source, RowNum))
InBlock.gif        
If Not (InstantText Is NothingThen
InBlock.gif            Combo.Text 
= InstantText
InBlock.gif        
End If
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Private ReadOnly Property DataGridTableGridLineWidth()Property DataGridTableGridLineWidth() As Integer
InBlock.gif        
Get
InBlock.gif            
If Me.DataGridTableStyle.GridLineStyle = DataGridLineStyle.Solid Then
InBlock.gif                
Return 1
InBlock.gif            
Else
InBlock.gif                
Return 0
InBlock.gif            
End If
InBlock.gif        
End Get
ExpandedSubBlockEnd.gif    
End Property

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Private Sub EndEdit()Sub EndEdit()
InBlock.gif        InEdit 
= False
InBlock.gif        Invalidate()
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Private Function GetText()Function GetText(ByVal Value As ObjectAs String
InBlock.gif        
If Value Is System.DBNull.Value Then Return NullText
InBlock.gif
InBlock.gif        
If Not Value Is Nothing Then
InBlock.gif            
Return Value.ToString
InBlock.gif        
Else
InBlock.gif            
Return String.Empty
InBlock.gif        
End If
InBlock.gif
ExpandedSubBlockEnd.gif    
End Function

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Private Sub HideComboBox()Sub HideComboBox()
InBlock.gif        
If Combo.Focused Then
InBlock.gif            
Me.DataGridTableStyle.DataGrid.Focus()
InBlock.gif        
End If
InBlock.gif        Combo.Visible 
= False
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Private Sub RollBack()Sub RollBack()
InBlock.gif        Combo.Text 
= OldVal
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Private Sub PaintText()Sub PaintText(ByVal g As Graphics, _
InBlock.gif                          
ByVal Bounds As Rectangle, _
InBlock.gif                          
ByVal Text As String, _
InBlock.gif                          
ByVal AlignToRight As Boolean)
InBlock.gif
InBlock.gif        
Dim BackBrush As Brush = New SolidBrush(Me.DataGridTableStyle.BackColor)
InBlock.gif        
Dim ForeBrush As Brush = New SolidBrush(Me.DataGridTableStyle.ForeColor)
InBlock.gif        PaintText(g, Bounds, Text, BackBrush, ForeBrush, AlignToRight)
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Private Sub PaintText()Sub PaintText(ByVal g As Graphics, _
InBlock.gif                          
ByVal TextBounds As Rectangle, _
InBlock.gif                          
ByVal Text As String, _
InBlock.gif                          
ByVal BackBrush As Brush, _
InBlock.gif                          
ByVal ForeBrush As Brush, _
InBlock.gif                          
ByVal AlignToRight As Boolean)
InBlock.gif
InBlock.gif        
Dim Rect As Rectangle = TextBounds
InBlock.gif        
Dim RectF As RectangleF = RectF.op_Implicit(Rect) ' Convert to RectangleF
InBlock.gif
        Dim Format As StringFormat = New StringFormat
InBlock.gif
InBlock.gif        
If AlignToRight Then
InBlock.gif            
Format.FormatFlags = StringFormatFlags.DirectionRightToLeft
InBlock.gif        
End If
InBlock.gif
InBlock.gif        
Select Case Me.Alignment
InBlock.gif            
Case Is = HorizontalAlignment.Left
InBlock.gif                
Format.Alignment = StringAlignment.Near
InBlock.gif            
Case Is = HorizontalAlignment.Right
InBlock.gif                
Format.Alignment = StringAlignment.Far
InBlock.gif            
Case Is = HorizontalAlignment.Center
InBlock.gif                
Format.Alignment = StringAlignment.Center
InBlock.gif        
End Select
InBlock.gif
InBlock.gif        
Format.FormatFlags = Format.FormatFlags Or StringFormatFlags.NoWrap
InBlock.gif        g.FillRectangle(Brush:
=BackBrush, Rect:=Rect)
InBlock.gif
InBlock.gif        Rect.Offset(
0, yMargin)
InBlock.gif        Rect.Height 
-= yMargin
InBlock.gif        g.DrawString(Text, 
Me.DataGridTableStyle.DataGrid.Font, ForeBrush, RectF, Format)
InBlock.gif        
Format.Dispose()
InBlock.gif
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public ReadOnly Property ComboBox()Property ComboBox() As ComboBox
InBlock.gif        
Get
InBlock.gif            
Return Combo
InBlock.gif        
End Get
ExpandedSubBlockEnd.gif    
End Property

ExpandedBlockEnd.gif
End Class

None.gif
测试代码
ExpandedBlockStart.gif ContractedBlock.gif Private   Sub Form_Load() Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
InBlock.gif        InitForm(DataGrid1)
InBlock.gif        
Dim namesDataTable As DataTable
InBlock.gif        namesDataTable 
= New DataTable("NamesTable")
InBlock.gif
InBlock.gif        namesDataTable.Columns.Add(
"Name"GetType(String))
InBlock.gif        namesDataTable.Columns.Add(
"Sex"GetType(String))
InBlock.gif
InBlock.gif        
Dim namesDataSet As DataSet = New DataSet
InBlock.gif        namesDataSet.Tables.Add(namesDataTable)
InBlock.gif        DataGrid1.DataSource 
= namesDataSet
InBlock.gif        DataGrid1.DataMember 
= "NamesTable"
InBlock.gif
InBlock.gif        AddGridStyle(DataGrid1)
InBlock.gif        AddData(namesDataTable)
InBlock.gif
ExpandedBlockEnd.gif    
End Sub

None.gif
ExpandedBlockStart.gifContractedBlock.gif    
Private   Sub AddGridStyle() Sub AddGridStyle(ByRef myGrid As DataGrid)
InBlock.gif        
Dim myGridStyle As DataGridTableStyle = New DataGridTableStyle
InBlock.gif        myGridStyle.MappingName 
= "NamesTable"
InBlock.gif
InBlock.gif        
Dim nameColumnStyle As DataGridTextBoxColumn = New DataGridTextBoxColumn
InBlock.gif        nameColumnStyle.MappingName 
= "Name"
InBlock.gif        nameColumnStyle.HeaderText 
= "Name"
InBlock.gif        myGridStyle.GridColumnStyles.Add(nameColumnStyle)
InBlock.gif
InBlock.gif        
Dim mydt As DataTable
InBlock.gif        mydt 
= New DataTable
InBlock.gif        mydt.Columns.Add(
"id"GetType(String))
InBlock.gif        mydt.Columns.Add(
"text"GetType(String))
InBlock.gif
InBlock.gif        
Dim newRowW As DataRow
InBlock.gif        newRowW 
= mydt.NewRow()
InBlock.gif        newRowW(
0= "0"
InBlock.gif        newRowW(
1= ""
InBlock.gif        
Dim newRowM As DataRow
InBlock.gif        newRowM 
= mydt.NewRow()
InBlock.gif        newRowM(
0= "1"
InBlock.gif        newRowM(
1= ""
InBlock.gif        mydt.Rows.Add(newRowM)
InBlock.gif        mydt.Rows.Add(newRowW)
InBlock.gif
InBlock.gif        
Dim comboxColumnStyle As New DataGridComboBoxColumnStyle(mydt, 11)
InBlock.gif        comboxColumnStyle.MappingName 
= "Sex"
InBlock.gif        comboxColumnStyle.HeaderText 
= "Sex"
InBlock.gif        comboxColumnStyle.Width 
= 100
InBlock.gif        myGridStyle.GridColumnStyles.Add(comboxColumnStyle)
InBlock.gif
InBlock.gif        myGrid.TableStyles.Add(myGridStyle)
ExpandedBlockEnd.gif    
End Sub

None.gif
ExpandedBlockStart.gifContractedBlock.gif    
Private   Sub AddData() Sub AddData(ByRef namesDataTable As DataTable)
InBlock.gif        
Dim dRow As DataRow = namesDataTable.NewRow()
InBlock.gif        dRow(
"Name"= "小站"
InBlock.gif        dRow(
"Sex"= ""
InBlock.gif        namesDataTable.Rows.Add(dRow)
InBlock.gif
InBlock.gif        dRow 
= namesDataTable.NewRow()
InBlock.gif        dRow(
"Name"= "小李"
InBlock.gif        dRow(
"Sex"= ""
InBlock.gif        namesDataTable.Rows.Add(dRow)
InBlock.gif
InBlock.gif        dRow 
= namesDataTable.NewRow()
InBlock.gif        dRow(
"Name"= "小吴"
InBlock.gif        dRow(
"Sex"= ""
InBlock.gif        namesDataTable.Rows.Add(dRow)
InBlock.gif
InBlock.gif        namesDataTable.AcceptChanges()
ExpandedBlockEnd.gif    
End Sub

None.gif
ExpandedBlockStart.gifContractedBlock.gif    
Private   Sub InitForm() Sub InitForm(ByRef myGrid As DataGrid)
InBlock.gif        myGrid.TabStop 
= True
InBlock.gif        myGrid.TabIndex 
= 1
ExpandedBlockEnd.gif    
End Sub

转载于:https://www.cnblogs.com/timsoft/articles/414084.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值