Creating a Search and Highlighting Found Item - vb.net-2010

I am able to create a search but I have no idea how to get the item I searched for to be highlighted in my list... here is what I have:
Dim foundItem As ListViewItem = ListView1.FindItemWithText(Me.searchText.Text, False,
0, True)
If (foundItem IsNot Nothing) Then
ListView1.TopItem = foundItem
foundItem.Selected() = True
End If
I am just not too sure how to get it to highlight so I can prove that it has been found... please help!!

Instead of using foundItem.Selected, should you try changing the item background color? I am just wondering if more than one items are found and you haven't set multiselect = true in your list, then it may not be able to select all items.

Related

How to get the Selected Text from Active Control in VB.NET?

Is there a way to get the selected text or highlighted text only from the Active Control? Active Control doesn't have .SelectedText option, so I used .Text
Example in the image.
I only highlighted "Rus" from the EnhacedTextBox.
ActiveControl.Text contains "Russia".
How do I get the SelectedText "Rus" to be set in Clipboard.SetDataObject() for copying?
Thanks a lot for your opinions and suggestions.
Do you mean you want to get selected text of a textbox ? If so,you can use TextBox.SelectedText property.
I am not sure if you are looking for this but if no, then i assume you are generating multiple textboxes from code behind/during design time ? If so, then try the following code to get the active textbox :
Private Sub GetTheText()
If Me.ActiveControl.[GetType]() = GetType(TextBox) Then
Dim textBox As TextBox = CType(Me.ActiveControl, TextBox)
Dim mytext = textbox.SelectedText
End If
End Sub
Hope this helps you
m_strGetText = Me.m_udtNavigationController.TemplateKeyAss.PrimaryTask.ActiveControl.Text.ToString()
Dim trial As EnhancedTextBox = TryCast(Me.m_udtNavigationController.TemplateKeyAss.PrimaryTask.ActiveControl, EnhancedTextBox)
Dim trial2 As String = trial.SelectedText().ToString()
Solution from #jmcilhinney.
trial2 now contains the Rus selected text. Thanks.

How to change the highlight color of the selected listview item

I tried do this code:
Dim hlcolor As Color = SystemColors.Highlight
hlcolor = color.green
But it doesn't seem to work for me. This is just an experiment.
Also, is it possible to leave a single column "without a highlight" when
fullrowselect = true?
Thanks in advance

Programmatically check a checkbox in ListView

I am trying to programmatically check a checkbox of a ListView (using VB & .NET 4).
The ListView lvVorschlag has been created in the designer, along with three elements. I then do the following:
Dim lviOptimal As New ListViewItem("Optimal")
lviOptimal.SubItems.Add(...) 'several SubItems are added
lvVorschlag.Items.Add(lviOptimal)
lvVorschlag.Items(0).Selected = True
All the SubItems are correctly added and the line lvVorschlag.Items(0).Selected = True does not give me an error. But nothing is checked. Any idea why?
Note: I also tried with lvVorschlag.Items("Optimal").Selected = True but it gives me an error saying that this object is Nothing. Too bad, referring by name would have been easier.
You should use the Checked property to check the item(s) you'd like:
lvVorschlag.Items(0).Checked = True
Set the focus on the item
Dim lviOptimal As New ListViewItem("Optimal")
lviOptimal.SubItems.Add(...) 'several SubItems are added
lvVorschlag.Items.Add(lviOptimal)
lvVorschlag.Items(0).focus()
lvVorschlag.Items(0).Selected = True
http://msdn.microsoft.com/en-us/library/y4x56c0b%28v=vs.100%29.aspx

Make ListView FindItemWithText match entire text

I have a ListView with two columns, and before enter a new item in the listview, I want to prevent entering a duplicate value, so I found ListView.FindItemWithText to accomplish that.
But I realized that if I enter 232323, and then enter 2323, which is different but starts with the same digits as the first entry, the function returns that item as a match.
I wonder if there is any way to match the whole text (exact text) to avoid the above.
Here is my code:
Dim ChkSIM As New ListViewItem
ChkSIM = lvItems.FindItemWithText("2323")
If Not ChkSIM Is Nothing Then
lblErrorSIM.Text = "Already in list"
End If
ListView.FindItemWithText has an overload to find only exact matches:
Dim ChkSIM As ListViewItem = lvItems.FindItemWithText("2323", True, 0, False)
For more information, see the documentation.

Why i cannot find context menu strip in my form?

I'am trying to find my context menu strip in my form but my code doesnt seem to displayed my desired output...here is my code:
Dim omnuStrip() As Object = oCollection.controls.find("mnuStrip", True)
Dim mnuStrip_ as ContextMenuStrip = DirectCast(omnuStrip,ContextMenuStrip)
mnuStrip_.Tag = "My Control"
it always return a empty array of objects...Am I doing wrong here? Please help..Thanks!
ContextMenuStrips are added to components, not controls, that's why you get an empty array.
Dim strip As ContextMenuStrip = Nothing
For Each component As Object In components.Components
strip = TryCast(component, ContextMenuStrip)
If strip IsNot Nothing Then Exit For
Next