2012-04-11 38 views
0

我有一个DataGridView,我有一个编辑Button与每一行关联。datagridview cellcontentclick事件没有时间完成

CellContentClick事件我动态删除,并在我的TableLayoutPanel

这种动态的删除和控制的建立创造textboxLabel控制数量服用一段时间也闪烁(当然那不是一个大issuse)。

但问题是如果有人持续点击各行的编辑buttons一段时间后整个TableLayoutPanel是一个完整的混乱。

根据我的情况发生这种情况我的CellContentClick事件没有完成时间,并且在事件完成之前点击其他行的编辑button。 而我无法处理这种情况

处理程序代码是在这里:

Private Sub gdXMLDOc1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles gdXMLDOc1.CellContentClick 
    Try 
     If lockThis = False Then 
      lockThis = True 

      If e.ColumnIndex = 0 Then 

       intPreviousRowIndex = intSelectedRowIndex 
       intSelectedRowIndex = e.RowIndex 

       gdXMLDOc1.Rows(intSelectedRowIndex).DefaultCellStyle.BackColor = Color.LightSkyBlue 

       If intPreviousRowIndex <> -1 And intPreviousRowIndex <> intSelectedRowIndex Then 

        arrQuestion(intPreviousRowIndex).questionText = Replace(txtQText_New.Text, """", "\""") 
        arrQuestion(intPreviousRowIndex).choice = Replace(txtOpt1_New.Text, """", "\""") 

        For i As Integer = 0 To arrQuestion(intPreviousRowIndex).cText_eng.Length - 1 

         arrQuestion(intPreviousRowIndex).cText(i).line = Replace(TableLayoutPanel1.GetControlFromPosition(2, i + 3).Text, """", "\""") 

        Next 

        For i = TableLayoutPanel1.RowCount - 1 To 3 Step -1 
         TableLayoutPanel1.RowCount = TableLayoutPanel1.RowCount - 1 
         TableLayoutPanel1.Controls.Remove(TableLayoutPanel1.GetControlFromPosition(0, i)) 
         TableLayoutPanel1.Controls.Remove(TableLayoutPanel1.GetControlFromPosition(1, i)) 
         TableLayoutPanel1.Controls.Remove(TableLayoutPanel1.GetControlFromPosition(2, i)) 
        Next 

       End If 

       TableLayoutPanel1.RowCount = 4 

       txtQText.Text = arrQuestion(intSelectedRowIndex).questionText_eng 
       txtOpt1.Text = arrQuestion(intSelectedRowIndex).choice_eng 
       txtQText_New.Text = arrQuestion(intSelectedRowIndex).questionText 
       txtOpt1_New.Text = arrQuestion(intSelectedRowIndex).choice 
       TableLayoutPanel1.RowCount = TableLayoutPanel1.RowCount - 1 
       Dim intRowIndex As Integer = TableLayoutPanel1.RowCount 

       For i As Integer = 0 To arrQuestion(intSelectedRowIndex).cText_eng.Length - 1 

        Dim lbl As Label = New Label() 
        lbl.AutoSize = True 
        lbl.Font = New System.Drawing.Font("Arial", 11.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) 
        lbl.Size = New System.Drawing.Size(73, 36) 
        lbl.TabIndex = 5 
        lbl.Text = "Line" + arrQuestion(intSelectedRowIndex).cText_eng(i).lineId.ToString 

        Dim TxtBox1 As dynamicTextBox = New dynamicTextBox() 
        TxtBox1.Text = arrQuestion(intSelectedRowIndex).cText_eng(i).line 

        Dim TxtBox2 As TextBox = New TextBox() 
        TxtBox2.Font = New System.Drawing.Font("Mangal", 13.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) 
        TxtBox2.MaxLength = 50000 
        TxtBox2.Size = New System.Drawing.Size(600, 37) 
        TxtBox2.TabIndex = 16 
        TxtBox2.Text = arrQuestion(intSelectedRowIndex).cText(i).line 

        TableLayoutPanel1.RowCount = TableLayoutPanel1.RowCount + 1 

        TableLayoutPanel1.Controls.Add(lbl, 0, intRowIndex) 
        TableLayoutPanel1.Controls.Add(TxtBox1, 1, intRowIndex) 
        TableLayoutPanel1.Controls.Add(TxtBox2, 2, intRowIndex) 


        intRowIndex = TableLayoutPanel1.RowCount 
       Next 

      End If 
      lockThis = False 
     End If 
    Catch ex As Exception 

    End Try 

End Sub 

回答

0

查找到SuspendLayout()和ResumeLayout()函数,以帮助闪烁。另一方面,没有任何代码很难确定。一种可能是如果您在任何地方使用Appliation.DoEvents()。这可能会导致一个线程在先前实例完成之前调用您的方法的问题,这可能会创建您描述的结果类型。而在事件处理程序代码运行

如果真的添加一个布尔值属性,测试,这样做

禁用按钮的

+0

嗨thanx。我已经添加了代码,你可以告诉我在哪里使用suspenlayout()和resumelayout()。 – 2012-04-13 08:28:46

+0

您将它们包装在创建/移动/ m的代码中,并使用UI进行隐藏。所以在你单元格中点击SuspendLayout();尝试{做UI的东西}终于{ResumeLayout();} – 2012-04-13 08:37:13

+0

sorryyy,但它也不工作:( – 2012-04-18 11:48:46

0

几种方法将其设置为true,做你的东西,它设置为false 。

已经完成了,看看你是否可以对“编辑请求”进行排队,并在后台做大量的工作。

第二个将是我的选择,为快速取胜。

而且....

“不断点击各行的编辑按钮后,”

把你所有的编辑按钮具有相同的处理?

给你做了

if (!_inhibit) 
{ 
    try 
    { 
    _inhibit = true; 
    // mess with template 
    } 
    finally 
    { 
    _inhibit = false; 
    } 
} 

只是不明白怎么可能出错。如果你把调试_inhibit = true,它应该永远不会到那里,除非处理程序代码已完成。鉴于这是事实,你认为错的不是。

+0

thanx托尼..我已经试过第一个1但它不工作 – 2012-04-12 08:59:16

+0

这是没有意义的。不是本地的方法吗? – 2012-04-12 11:18:14

+0

是它的类成员........ – 2012-04-12 11:32:06

0

使用电池clickevent,而不是像这样

私人小组DataGridView1_CellClick(发送者为对象,E作为DataGridViewCellEventArgs)处理DataGridView1.CellClick

单元格内容点击工作时对表中的文本中的用户点击造成令人困惑的用户体验

相关问题