I have a ListView named lvSelectCustomer.
I loaded some values in lvSelectCustomer. The lvSelectCustomer has 5 columns. Column[2] and Column[4] are hidden by set its Width into zero. Because i don't want to show those colums while runtime. All data are loaded successfully. No problem in loading data. The problem is...
I activate an event of lvSelectCustomer
private void lvSelectCustomer_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{
string strSelectedCustomerIndex = lvSelectCustomer.FocusedItem.Index.ToString();
MessageBox.Show(strSelectedCustomerIndex);
}
Inside that event i created a string called strSelectedCustomerIndex . And set the focused item index to that string. While we select a row in lvSelectedCustomer at the 1st time the message box is coming and shows the index of that selected/focused row. Then after that, if i will select an another row from lvSelectedCustomer, an error is coming. Which is...
System.NullReferenceException: 'Object reference not set to an instance of an object.'
System.Windows.Forms.ListView.FocusedItem.get returned null.
I need the selected row's index while every row selection change. Please help me. I am not that much good in c#. Please help to sort it out. Thanks in advance.
What I have tried:
private void lvSelectCustomer_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{
string strSelectedCustomerIndex = lvSelectCustomer.FocusedItem.Index.ToString();
MessageBox.Show(strSelectedCustomerIndex);
}