cancel
Showing results for 
Search instead for 
Did you mean: 

How can I get the text which I selected in the listbox?

Valued Contributor
Valued Contributor

I got a problem that I made a listbox and some data inside, but how can I get the data which I selected in the listbox? I use NX6.0.  VB .NET

Best Regards
Christian
4 REPLIES

Re: How can I get the text which I selected in the listbox?

Legend
Legend

Is this a wndows form listbox or a block styler list box?

 

For windows form listbox use listbox.selecteditem.

 

For block styler listbox.selecteditemindex or listbox.selecteditemstring.

 

Re: How can I get the text which I selected in the listbox?

Siemens Phenom Siemens Phenom
Siemens Phenom

 

We have an example program in the Solution Center called

Sample NX Open .NET Visual Basic program : report block styler list box selected items

 

You can also find it if you search for the string "nx_api4097".

 

this is the essential bit from the update callback:

 

        
            If block Is list_box0 Then

                lw.WriteLine("Current SelectedItems are:")
                Dim pl As PropertyList = list_box0.GetProperties()
                Dim items() As String = pl.GetStrings("ListItems")
                Dim selected() As Integer = pl.GetIntegerVector("SelectedItems")
                For Each picked As Integer In selected
                    lw.WriteLine("  " & items(picked))
                Next

                ' This demonstrates limiting the number of selected items to 2
                If selected.Length > 2 Then
                    Dim twomax() As Integer = {selected(0), selected(1)}
                    pl.SetIntegerVector("SelectedItems", twomax)
                End If
                pl.Dispose()
            End If

Re: How can I get the text which I selected in the listbox?

Valued Contributor
Valued Contributor
Hi SteveLabout

Thank you very much! You give me a big help!
Best Regards
Christian

Re: How can I get the text which I selected in the listbox?

Valued Contributor
Valued Contributor
Hi Technisites
It was used in a block styler list box, listbox.selecteditemindex or listbox.selecteditemstring can not be used in NX6.0, but thanks anyway!
Best Regards
Christian