.Net 2003 CF Listbox Click event does not fire.

  • Thread starter Thread starter Pat
  • Start date Start date
P

Pat

using .Net 2003 CF anybody else seen this..



Listbox Click event does NOT fire.

Private Sub LST_Click (ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles LST.Click

End Sub

Listbox SelectedIndexChanged event Fires instread.

Private Sub LST_SelectedIndexChanged (ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles LST.SelectedIndexChanged

End Sub



-Pat
 
This is expected behavior. The Click event is not available in the .NET CF
for the ListBox control.
 
How about this one...
If you use a treview...Load it up like this and click Sub Item2
..Fullpath is = "Item1\Sub Item5"

you get Sub Item5 ???? Sub Item3, you get Sub Item5 ????


-Item1
| +--Sub Item1
| +--Sub Item2 <--Click here
| +--Sub Item3
| +--Sub Item4
| +--Sub Item5
+-Item2

Try it.. I hope this is NOT by design..!..

-Pat
 
I can't reproduce that. Did you fill your TreeView during design time or during run time? How do you get the full path? I just created your sample, initializing the TreeView during design time. Using the AfterSelect event I always get the correct and full path back.

private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
MessageBox.Show(treeView1.SelectedNode.FullPath);
}
If you send us some code we might be able to help.


--
Regards,

Maarten Struys
PTS Software bv
----
 
I have to admit that I am not too good in VB.NET. However, I converted your
sample code to C# and it runs as expected, not the unexpected results I got
with your VB.NET code. Tomorrow I will take another look at the VB.NET code
and try to get it working (or give up of course) so bear with me :-).

--
Regards,

Maarten Struys
PTS Software bv
----
 
Hey Pat,

I took a look at your code and there is a problem in it. When you are
expanding your tree in the Tre_AfterSelect subroutine you create one single
new instance of a TreeNode (P). You are adding that TreeNode to the tree and
you are re-using it. That is the cause of the problem, since you have to
create new TreeNodes for each element you are adding. So, if you are
creating a new TreeNode inside your while loop your problem will be solved.
I re-arranged the code a bit, and this sample is working in VB.NET as well:

Public Class Form1

Inherits System.Windows.Forms.Form

Friend WithEvents TRE As System.Windows.Forms.TreeView

Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

MyBase.Dispose(disposing)

End Sub

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Private Sub InitializeComponent()

Me.MainMenu1 = New System.Windows.Forms.MainMenu

Me.TRE = New System.Windows.Forms.TreeView

'

'TRE

'

Me.TRE.ImageIndex = -1

Me.TRE.Location = New System.Drawing.Point(17, 18)

Me.TRE.SelectedImageIndex = -1

Me.TRE.Size = New System.Drawing.Size(202, 172)

'

'Form1

'

Me.Controls.Add(Me.TRE)

Me.Menu = Me.MainMenu1

Me.MinimizeBox = False

Me.Text = "Form1"

End Sub

#End Region

Private Sub Tre_AfterSelect(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.TreeViewEventArgs) Handles TRE.AfterSelect

MsgBox(TRE.SelectedNode.FullPath)

If e.Node.Tag = "L" Then

TRE.BeginUpdate()

Dim N As TreeNode = e.Node

Dim D As Integer = 0

For D = 0 To 9

N.Nodes.Add(New TreeNode(D.ToString))

Next

N.Expand()

TRE.EndUpdate()

End If

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

CreateTree()

End Sub

Private Sub CreateTree()

Dim X As Integer

TRE.BeginUpdate()

TRE.Nodes.Clear()

For X = 1 To 26

Dim N As New TreeNode

N.Text = Chr(X + 64).ToString

N.Tag = "L"

TRE.Nodes.Add(N)

Next

TRE.EndUpdate()

End Sub

End Class

'-----------------------------------------------------------------


--
Regards,

Maarten Struys
PTS Software bv
----
 
Back
Top