Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language:
Expertise: Beginner
Aug 6, 1997

Use A Class To Convert Code

In VB3 if you wanted to convert your code from one custom control to another, there were no options other than changing your code. By writing the proper class you can make use of your current syntax with a different control. This code demonstrates how to write a VB class to change standard list-box syntax to use a ListView control. MyList.AddItem and .RemoveItem methods and the .Text property will interface to the ListView Control using this class:
 'Form1 would have a listView control on it
'dim a module wide object variable
Dim MyList As Object

Private Sub Form_Load()
	'create an instance of our class
	Set MyList = New FakeList
	'tell the class what control to use
	Set MyList.ListItem = ListView1
End Sub

'The Class code follows
'This holds the listview control
'that we will interface with
Public ListItem As ListView

Public Sub AddItem(sString As String)
	'convert AddItem to Add
	ListItem.ListItems.Add , , sString
End Sub

Public Sub RemoveItem(lItem As Long)
	'Convert RemoveItem to Remove
	ListItem.ListItems.Remove lItem
End Sub

Public Property Get Text() As String
	'Get the text from the selected item
	Text = ListItem.SelectedItem.Text
End Property

Public Property Let Text(sString As String)
	'set the text in the selected item
	ListItem.SelectedItem.Text = sString
End Property
MicroHelp Uninstaller
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date