Hello, I am trying to set the selection to a component within a listbox. I have attempted to use the following:
But neither have been giving me the desired result, which is for it to highlight the components I put into those functions, Can anyone explain this behavior to me and how I should proceed to get my desired result? It works fine if you do it manually, but I have a catch in there for when the user swaps components without applying the changes. When this catch goes off, it asks the user whether they would like to keep modifying the component, and if they select yes, the GUI should re-highlight that component. Thank you in advance for your help.
Not sure I understand the question correctly but are you trying to set the selection in the list box or highlight "something" (in nx session) based on the selection in the list box? If it is the 1st option I use the following method/approach (sometime)
Dim myListofNames As New List(Of String) ' list is returned by another function 'display list in listbox theListBox1.SetListItems(myListofNames.ToArray) 'in this example select the 1st item as it only contains one item If myListofNames.Count = 1 Then theListBox1.setSelectedItemStrings(myListofNames.T
oArray) End if 'otherwise one needs to create a new string array 'containing the string ie.e item you want to select in the Lbox 'let's say that that you want to create an array of name which contains a specific word Dim myListofSelectedNames As New List(Of String) Dim swordtofind as String ="part1_" Dim pos As Integer = 0 For Each sname As String In myListofNames pos = InStr(sname,swordtofind) if pos <> 0 Then myListofSelectedNames.Add(sname) Next theListBox1.setSelectedItemStrings(myListofSelecte dNames.ToArray)
Sorry for the muddy explanation. I attempted to use the methods you suggested originally and while it executed correctly and selected the component, it did not highlight it within the List Box. Typically when you manually select something within the listbox, it highlights that row(s) blue. When I set the selection with the code, it does not highlight that row blue.
Not the end of the world, but it throws off our end users to not have something highlighted like that.