I have this little code that works but I would like to know if there is an easier way to do this..
Dim itmIndex As Integer = 0 For Each aItem In lstObjectMain.SelectedObjects Dim selIndex As Integer = lstObjectMain.SelectedIndices.Item(itmIndex).ToString Debug.Print(lstObjectMain.Items(selIndex).Text) itmIndex += 1 Next
First of all use For counter, not for each:
For x=0 to lstObjectMain.SelectedObjects.Count-1...
You can use LINQ as well:
Dim ExportText as New List(Of String) = (From ActObject As Object In lstObjectMain.SelectedObjects Select ActObject.TextOrSomething).ToList
SelectedObjects gives you your model objects. Once you have those, you can get whatever bit of information you want to display.
SelectedObjects
var names = this.lstObjectMain.SelectedObjects.Cast<YourModel>().Select(x => x.Name); Debug.WriteLine(string.Join(",", names.ToArray()));
Log in to post a comment.
I have this little code that works but I would like to know if there is an easier way to do this..
First of all use For counter, not for each:
For x=0 to lstObjectMain.SelectedObjects.Count-1...
You can use LINQ as well:
Dim ExportText as New List(Of String) =
(From ActObject As Object In lstObjectMain.SelectedObjects Select ActObject.TextOrSomething).ToList
SelectedObjectsgives you your model objects. Once you have those, you can get whatever bit of information you want to display.