Need dotnet equivalent code to VB6.GetItemString and VB6.SetItemSt


S

SAL

Can anyone tell me what the dotnet equivalent is to the following code:

Dim strListItem As String

strListItem = VB6.GetItemString(Me.lstCall, Me.lstCall.Items.Count -
1)
strListItem = strListItem & "."
VB6.SetItemString(Me.lstCall, Me.lstCall.Items.Count - 1, strListItem)

I want to remove the Microsoft.VisualBasic.Compatibility reference and make
my app a true .net app.

Thanks,
 
Ad

Advertisements

T

Tom Shelton

Can anyone tell me what the dotnet equivalent is to the following code:

Dim strListItem As String

strListItem = VB6.GetItemString(Me.lstCall, Me.lstCall.Items.Count -
1)
strListItem = strListItem & "."
VB6.SetItemString(Me.lstCall, Me.lstCall.Items.Count - 1, strListItem)

I want to remove the Microsoft.VisualBasic.Compatibility reference and make
my app a true .net app.

Thanks,
Well, there isn't one exactly.... Those functions are there because
the .NET ListBox does not have an ItemData property like it did in
VB6. The reson for this is that ListItems do not need to be simple
strings. The most common use of the ItemData was to associate an
Integer value with an entry in the listbox (often a record id) - but
that's not needed in .NET. For example:

class Person
private _id as integer
private _firstName as string
private _lastName as string

public property ID as integer
get
retrun id
end get
set (byval value as integer)
_id = value
end set
end property

' properties for first and last name

' full name property
public readonly property string FullName
get
return _lastName & ", " & _firstName
end get
end property
end class

Now, you can fill a list box with a bunch of these objects:

listbox1.DisplayMember = "FullName"

dim p as new person()
p.id = 1
p.firstname = "tom"
p.lastname = "shelton"

listbox1.items.add(p)

Now you would see:
shelton, tom

in your ListBox. Now, obviously in this case you would probably put a
whole bunch of objects in there from some source - but this is just a
silly example :)

No, if you needed the id of the selected item, you would do somthing
like:

if not listbox1.selecteditem is nothing then
dim p as person = directcast(listbox1.selecteditem, person)

id = p.id
end if


Anyway, the thing to take from this is that the listbox in .NET
doesn't need an itemdata property, because you can stick arbitrary
objects in it which can have as much or little data associated with
them as you want.... You might want to become familiar with the
DisplayMember and ValueMember properties of the ListBox.
 
S

SAL

Thanks Tom.

I've mostly developed with C#, VB6 or VB.net, and until now I never
converted a VB6 project to .net. So, I never had a need to know the
differences between VB6 and VB.net, and I haven't develop in VB6 in nearly 6
years.

I migrated the to:

Dim strListItem As String
strListItem = Me.lstCall.Items(Me.lstCall.Items.Count - 1)
strListItem += "."
Me.lstCall.Items(Me.lstCall.Items.Count - 1) = strListItem

I haven't tested it yet, but it compiles fine. I'm not sure who wrote this
code but it's suppose to update a timer in the app.
 
Ad

Advertisements

C

Cor Ligthert[MVP]

SAL,

Be aware that a DataGridView is in fact a multicolumn ListBox from which you
can remove the column and rowheader

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top