问题描述
我有一个名为lvSelectCustomer的ListView。
我在lvSelectCustomer中加载了一些值。 lvSelectCustomer有5列。通过将其宽度设置为零来隐藏列[2]和列[4]。因为我不想在运行时显示那些列。所有数据都已成功加载。加载数据没问题。问题是......
我激活lvSelectCustomer事件
private void lvSelectCustomer_ItemSelectionChanged(object sender,ListViewItemSelectionChangedEventArgs e)
{
string strSelectedCustomerIndex = lvSelectCustomer.FocusedItem.Index.ToString();
MessageBox.Show(strSelectedCustomerIndex);
}
在该事件中,我创建了一个名为 strSelectedCustomerIndex的字符串。并将焦点项索引设置为该字符串。当我们在第一次在lvSelectedCustomer中选择一行时,消息框即将到来,并显示所选/焦点行的索引。然后,如果我将从lvSelectedCustomer中选择另一行,则会出现错误。这是...
System.NullReferenceException:'对象引用未设置为对象的实例。'
System.Windows.Forms.ListView.FocusedItem.get返回null。
我需要选择行的索引,而每行选择都会改变。请帮我。我在c#中没那么好。请帮忙整理一下。在此先感谢。
我尝试过:
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);
}
推荐答案
if (lvSelectCustomer.SelectedItems.Count != 0 )
这篇关于更改列表视图中的所选项时出错。救命! ! ! ! !的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!