开发者

TreeView update bug in the .net framework

Consider the following code:

Dim Working As Boolean = False
Private Sub TreeView1_AfterCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterCheck
    If Working Then Exit Sub
    Working = True
    e.Node.Checked = Not e.Node.Checked
    Working = False
End Sub

Private Sub TreeView1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseClick
    If e.Button = Windows.Forms.MouseButtons.Right Then MsgBox("Checked = " & TreeView1.SelectedNode.Checked)
End Sub

Where TreeView1 is a TreeView added to the form, with CheckBoxes set to true and one node added. The code basically cancel any node checking occuring on the form.

Single-clicking the top node to check it works well : your click is immediately canceled. Yet if you double-click the checkbox, it will display a tick. But verifying the check state through a right click will yield a Checked = False dialog.

How come? Is it a bug (I'm using the latest .Net Framework 4.0, and he same occurs in 2.0), or am I doing something wrong here? Is there a work around?

EDIT: Additionally, the MouseDoubleClick event is not raised before you click once again.

EDIT 2: Posted a bug report at Microsoft Connect

ED开发者_如何学JAVAIT 3: See this bug report as well.


This appears to be a bug to me. The checkbox is clearly checked on the screen, yet the API states that it is not checked.

One question that comes to mind is, what are you trying to accomplish? You've got code that cancels a user's action of checking the checkbox... Why have the checkbox to begin with if you're intention is to not allow it to be checked?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜