|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Creating Multiple Listviews in CodeI have a question regarding the creation of multiple listviews during run-time. I currently have code that uses a loop to create 5 listviews with identical properties (excep for the name). Once a listview is created, it s filled with data loaded from a txt file and then the loop iterates too creat the next listview. My problem is that while I am able to create and fill the listviews, I am not actually able to perform any actions on any of the listviews except for the one that was created last. By this I mean that if i were to select an item in a particular listview, only the listview created last would raise an event (for exmple listview.SelectedIndexChanged). I know the problem has to do with eveny handling but i'm not sure exactly what I have to do in order to get each listview to handle events seperately. I would appreciate any help on this subject. If it helps I can post my code... Thanks, Waqas Hi you need the addhandler statement, have a look at this example it adds
the click event to all 3 listview Private Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim myList As ListView For i As Integer = 0 To 2 myList = New ListView myList.Name = "list" & CStr(i) myList.Size = New Size(55, 55) myList.Location = New Point(60 * (i + 1), 10) myList.Items.Add("Hi I'm number" & CStr(i)) AddHandler myList.Click, AddressOf ListView_Click Me.Controls.Add(myList) Next End Sub Private Sub ListView_Click(ByVal sender As Object, ByVal e As System.EventArgs) MsgBox(DirectCast(sender, ListView).Name) End Sub hope this helps, Greetz Peter -- Show quoteHide quoteProgramming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. (Rich Cook) "Waqas101" <waqas78***@yahoo.co.uk> schreef in bericht news:1144671689.715200.305050@v46g2000cwv.googlegroups.com... > Hi, > > I have a question regarding the creation of multiple listviews during > run-time. I currently have code that uses a loop to create 5 listviews > with identical properties (excep for the name). Once a listview is > created, it s filled with data loaded from a txt file and then the loop > iterates too creat the next listview. > > My problem is that while I am able to create and fill the listviews, I > am not actually able to perform any actions on any of the listviews > except for the one that was created last. By this I mean that if i were > to select an item in a particular listview, only the listview created > last would raise an event (for exmple listview.SelectedIndexChanged). > > I know the problem has to do with eveny handling but i'm not sure > exactly what I have to do in order to get each listview to handle > events seperately. > > I would appreciate any help on this subject. If it helps I can post my > code... > > Thanks, > > Waqas > You're welcome
-- Show quoteHide quoteProgramming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. (Rich Cook) "Waqas101" <waqas78***@yahoo.co.uk> schreef in bericht news:1144741616.437836.26810@u72g2000cwu.googlegroups.com... > Hey thanks a lot that worked great! > > Cheers, > > Waqas >
SQL query on Datatables [VB 2005]
Datagridview cell background color? simple thread question arraylist to use in another form Drawing a square (or circles) before each item of a treeview Textbox Click Event needed. Disable objectdatasource-control 'System.Security.SecurityException' with .NET 2005 Only Validating Data in a DataGrid private font collection - delete |
|||||||||||||||||||||||