Hi,
I have a form with two listviews. The second listview loads items based on the focused item of the first listview. I have the following code to check the items in the first listview:
If listView1.Items.Count > 0 Then
If myIndex > -1 Then
lstView1.Items.Item(0).Selected = True
listView1.Items.Item(0).Focused = True
End If
If listView1.FocusedItem Is Nothing Then
listView1.FocusedItem = listView1.Items.Item(0)
End If
listView1.FocusedItem.EnsureVisible()
End If
I have an object reference not set to an instance of object error caused by the line listView1.FocusedItem.EnsureVisible(), but the strange thing is that I have assigned the focused item property of the listview and also set the listview item to be focused by using the focus method in the code, and the focuseditem is still null when I checked it with VS debugger. I have spent many hours on this and couldn't figure out why I have this exception. Does anybody know how to resolve this?
Thanks in advance!