2012年(101)
分类: 嵌入式
2012-06-12 23:34:39
//如果不加listview.SelectedIndices.Count>0判断,将导致获取listview.Items[]索引超界的异常
if (lv_backup_file.SelectedIndices != null && lv_backup_file.SelectedIndices.Count>0)
{
ListView.SelectedIndexCollection c = lv_backup_file.SelectedIndices;
backup_file = lv_backup_file.Items[c[1]].Text;
show_restore_info.Text += backup_file;
}
//设置listview的点击事件,命名为lv_selected
//以下方法经过验证
private void lv_selected(object sender, EventArgs e)
{
//清空textbox显示
if (show_restore_inzfo.Lines.Count() > 1)
{
show_restore_info.Text = null;
}
//开始选择备份文件.注意无法多选.
if (lv_backup_file.SelectedIndices != null && lv_backup_file.SelectedIndices.Count > 0)
{
ListView.SelectedIndexCollection c = lv_backup_file.SelectedIndices;
backup_file = lv_backup_file.FocusedItem.SubItems[1].Text;
show_restore_info.Text += "己选择文件: ";
show_restore_info.Text += backup_file;
show_restore_info.Text += "\r\n";
}
}