Hi all,
can anyone tell me how to write the .net code for vb6.setitemdata for combobox or listbox item?

Recommended Answers

All 10 Replies

There is no such thing as vb6.setitemdata.

You need to give us more information on what you mean.:)

Hi AndreRet,

Im converting some vb6 code to vb.net. in some places we are using
vb6.setitemdata(combobox,Combobox.selectedindex,Value)
i want to write the Equivalant code. basically i dont know vb6 much.

I have asked the moderators to move this to vb.Net. I'm sure you will get the solution there. There is a fair amount of change in the code you need from vb6 to .net.:)

I will in the interim see if I can work towards a solution here.

Thanks AndreRet,
It would be great help if you can get me the sollution.
waiting for your reply soon..:)

Hope this is what you are looking for -

Private Sub ReadData()
        Dim i As Integer
        Dim cmdUser As New SqlCommand
        Dim daUser As New SqlDataAdapter
        Dim dsUser As New DataSet
        Dim dtUser As New DataTable
        Dim conn As SqlConnection
 
        conn = GetConnect()
        Try
 
            cmdUser = conn.CreateCommand
            cmdUser.CommandText = "SELECT * FROM User"
            daUser.SelectCommand = cmdUser
            daUser.Fill(dsUser, "User")
            dtUser = dsUser.Tables("User")
            For i = 0 To dtUser.Rows.Count - 1
                cmbUserId.Items.Add(dtUser.Rows(i).Item(0))
            Next
 
        Catch ex As Exception
            MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Error conection!!")
        End Try
        conn.Close()
    End Sub

cmbUserId.Items.Add(dtUser.Rows(i).Item(0))
this code will adapted with your database, in mydatabase id user in item(0) / first coloumn

Thanks for reply,
Im adding the items to combo using objects.
I just want to know what is vb6.Setitemdata will do?
i think it just Sets the valuemember of combobox at perticular index.

Thanks.

I never worked with this before. In vb6 you could set the ItemData in the properties, which is not supported in vb.net though. I am as clueless as you here.;)

Have a look at THIS thread from MS, maybe it will help.

what your code in vb6 for vb6.Setitemdata?

VB6.SetItemData(combobox1, combobox1.Items.Count - 1, False)

This is the code i need to convert. is this code setting the valuemember of combobox at the perticlaur index?

.NET Combo Box or list box doesn't support item data. You can create your own class if you want to keep using SetItemData.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.