|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Option strict on and detecting a listview NameI'm modifying a multi-paneled form which has 8 different listviews, To allow sorting by columns I've had to add a diffrerent handler Sub for each of them eg. Private Sub ListViewOne(ByVal o As Object, ByVal e As ColumnClickEventArgs) ... End sub If I could somehow detect the o.Name property of the sender object I could identify the ListView and make the Sub handle all 8 of the ListViews. However because "Option Strict On" disallows late binding, I can't find a way of accessing the properties of the sending object. PS: I'm adding the handler to each listview as I populate them with "AddHandler" Any polite ideas ? hmmm Searched for ages for an answer so as luck would have it, I found
an answer 10 minutes after my post :-) The solution: If DirectCast(o, Control).Name = "ListViewOne" Then MsgBox("Yep, this is ListViewOne") End If A big thank you for the solution goes to : Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ Who answered a similar question. James wrote:
> Private Sub ListViewOne(ByVal o As Object, ByVal e As Or, better still, because you might rename one of the ListView controls > ColumnClickEventArgs) > ... > End sub > > If I could somehow detect the o.Name property of the sender object I > could identify the ListView and make the Sub handle all 8 of the > ListViews. later on and forget to change this routine, how about Private Sub AnyListView_ColumnClick( _ ByVal sender as Object _ , ByVal e as ColumnClickEventArgs _ ) If sender Is ListView1 Then ... ElseIf sender Is ListView2 Then ... End If End Sub Or, if you don't need to /differentiate/ between them (i.e. you want all the ListViews to do the /same/ thing when you click on them Private Sub AnyListView_ColumnClick( _ ByVal sender as Object _ , ByVal e as ColumnClickEventArgs _ ) If TypeOf sender Is ListView Then With DirectCast( sender, ListView ) ... End With End If End Sub HTH, Phill W.
Getting Exception on Command Line Args, but works within IDE debug
Datagrid binding problem Mutable Types and Read-Only Fields Maximize form problem->bottom hidden by start bar Is there a way to see if a file is in use? backgroundworker VS2005 - Passing NumericUpDown into a class method? Retrieving a list of available fonts on system. ReadAllText, special characters DX9 SDK (Feb 2006) / .NET 2.0 |
|||||||||||||||||||||||