Upgrade VB6 to .net NewIndex & OLE1

1.3k views Asked by At

I am trying to get my conversion fixed from a VB6 application over to a VB.net 2010 application. Everything went well but for a few sleeted listbox NewIndex and OLE control.

Below are the trouble lines that could not seem to be converted:

VB6.SetItemData(lstARCurrent, lstARCurrent.NewIndex, (.Fields("approval_s").Value))
OLE1.CreateLink(strFileName)
OLE1.DoVerb(vbOLEOpen)

If anyone has any incite to correct this issue then that would be great as i have not found a way around these errors!

Thanks!

David

1

There are 1 answers

0
Scott Whitlock On BEST ANSWER

That's weird. In VB6 you'd do this:

lstARCurrent.Add(someString)
lstARCurrent.ItemData(lstARCurrent.NewIndex) = myLongKey

That was a nice way to store a string into a list box but associate a database ID with it.

I assume your VB6.SetItemData routine is doing the same thing. However, in .NET that won't work. For one thing, items in list boxes in VB6 are 1 based instead of 0 based, so that'd probably cause issues, but the .NET list box most likely doesn't have a .NewIndex property. Neither does a listbox have an ItemData array property.

The new way to handle this is to add an entire object and let the .ToString method tell the listbox what to display (sorry for C#, my VB.Net is rusty):

class MyItem
{
    public int MyKey { get; set; }
    public string MyStringValue { get; set; }
    public override string ToString()
    {
        return this.MyStringValue;
    }
}

Then just add the item:

lstARCurrent.Items.Add(new MyItem() { MyKey = 3, MyStringValue = "abc" });

It will display abc but you can use lstARCurrent.SelectedItem to get back the MyItem object.