不会触发EditingControlShowing [英] EditingControlShowing isn't fired
问题描述
我在VB.Net 2008中制作了一个用户控件(UC)来管理一个专门从主程序中获取网格的DataGridView。
我给了我的UC一个属性,告诉网格colmun是一个文本框,组合框还是复选框,所以当我在UC构建网格结构时知道列规范。
它运行正常,但当我尝试输入任何定义为文本框,组合框或复选框的单元格时,DataGridView控件不会触发事件EditingControlShowing。
构建网格的代码
Hi,
I've made a user-control (UC) in VB.Net 2008 to manage dinamically a DataGridView specializing the grid from host program.
I've gifted my UC of a property that tell to grid if a colmun is a textbox, combobox or checkbox, so when I when the UC build the grid structure know the column specification.
It works fine, but when I try to enter in any of cell that are defined as textbox, combobox or checkbox the DataGridView control not fires event EditingControlShowing.
The code that buil grid
Private Sub GrdStyleFormat(ByRef RS As Data.DataTable)
Dim tblGrd As DataTable
Dim i, j As Integer
If Not IsNothing(MSFlexGrid1.DataSource) Then
MSFlexGrid1.DataSource = Nothing
MSFlexGrid1.DataMember = ""
MSFlexGrid1.Rows.Clear()
MSFlexGrid1.Columns.Clear()
With MSFlexGrid1.ColumnHeadersDefaultCellStyle
.Font = Control.DefaultFont
End With
End If
If IsNothing(RS) Then
tblGrd = New DataTable
tblGrd.TableName = "TBLGRID"
Else
tblGrd = RS
End If
If Me.FormatString.Trim.Length > 0 Then
DefineBestColumnsWidth(Me.FormatString)
End If
Try
If tblGrd.TableName = "TBLGRID" Then
For i = 0 To szHdr.Length - 1
Dim DF As New DataColumn
DF.ColumnName = m_ColEhnProperty(i).DataField.ToUpper
tblGrd.Columns.Add(DF)
Next
tblGrd.NewRow()
Else
For i = 0 To szHdr.Length - 1
If m_ColEhnProperty(i).IsHidden Then
MSFlexGrid1.Columns.Add(m_ColEhnProperty(i).DataField.ToUpper, szHdr(i))
MSFlexGrid1.Columns(i).Visible = False
Else
If m_ColEhnProperty(i).IsTextBox Then
Dim DGC As New DataGridViewTextBoxColumn
DGC.HeaderText = szHdr(i)
DGC.Name = m_ColEhnProperty(i).DataField.ToUpper
DGC.Width = m_ColEhnProperty(i).ColWidth
DGC.ReadOnly = True
DGC.DefaultCellStyle.BackColor = Color.AliceBlue
If m_ColEhnProperty(i).ColAlignment = HorizontalAlignment.Right Then
DGC.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
End If
MSFlexGrid1.Columns.Add(DGC)
ElseIf m_ColEhnProperty(i).IsCheckbox Then
Dim DGC As New DataGridViewCheckBoxColumn
DGC.HeaderText = szHdr(i)
DGC.Name = m_ColEhnProperty(i).DataField.ToUpper
DGC.Width = m_ColEhnProperty(i).ColWidth
DGC.ReadOnly = True
MSFlexGrid1.Columns.Add(DGC)
Else
Dim DGC As DataGridViewTextBoxColumn = New DataGridViewTextBoxColumn
DGC.HeaderText = szHdr(i)
DGC.Name = m_ColEhnProperty(i).DataField.ToUpper
DGC.Width = m_ColEhnProperty(i).ColWidth
DGC.ReadOnly = True
If m_ColEhnProperty(i).ColAlignment = HorizontalAlignment.Right Then
DGC.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
End If
MSFlexGrid1.Columns.Add(DGC)
End If
End If
Next
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
tblGrd.DefaultView.AllowNew = False
tblGrd.DefaultView.AllowDelete = False
MSFlexGrid1.DataMember = tblGrd.TableName
MSFlexGrid1.DataSource = tblGrd
end sub
我在CellEnter活动中添加了代码
I've added in the CellEnter event the code
<pre lang="vb">
Private Sub MSFLexGrid1_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles MSFLexGrid1.CellEnter
Debug.Print(Me.DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).GetType.ToString & " " & Me.DataGridView1.EditMode.ToString)
End Sub
查看列对象类型,结果是正确的
我不是为什么!!
我在网上搜索但是找不到解释如何解决我的问题
谢谢
to view the column object type and the result is correct
I don't why !!
I've search on the net but haven't find somewhat that explain how to solve my problem
Thanks
推荐答案
这篇关于不会触发EditingControlShowing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!