我失去了我的ListView选择事件处理的东西 [英] Am I missing something with my ListView selection event handling

查看:104
本文介绍了我失去了我的ListView选择事件处理的东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

...或者是C#列表视图真的是这样管理的噩梦?

...or are c# listviews really such a nightmare to manage?

好吧,我工作的问题很简单。或者至少看起来是这样:

Okay the problem I'm working on is very simple. Or at least it appears to be so:

我有包含在单独的行客户订单信息的文本文件。数据项是由分号分隔。

I have a text file which contains information about customer orders on separate lines. The data items are separated by semi-colons.

我的形式通过这些命令迭代,使项目信息到哈希表,并把每个哈希表到主哈希表。关于每个订单(产品/订单#/客户名称/客户#)有些汇总信息显示在列表视图我用排序的列分隔。下面列表视图是文本框为订单详细信息S $ P $垫的横跨三个选项卡的编辑区域选项卡控件。

My form iterates through these orders, puts the item information into hashtables and puts each hashtable into a master hashtable. Some summary information about each order (product/order#/customer name/customer#) is displayed in my listview separated by sortable columns. Below the listview is a tab control with textboxes for the editable parts of the order details spread across three tabs.

下面是我想什么情况发生:

Here is what I would like to happen:


  • 用户点击一个条目:标签控制文本框填充订单明细

  • 用户编辑细节标签控件。

  • 用户点击另一项命令:确认消息检查的变动,应承诺,如果是,那么细节应保存回在ListView更新有关Hashtable和显示

  • 用户选择多个列表视图项:顶部的项目,应在标签控件编辑

  • 用户presses在窗体顶端在工具条删除项目(S)按钮:在项目(S)从哈希表中移除,ListView控件更新以反映删除。该文本框都重新设置为空白整个标签控制。

这在我看来,像pretty普通,合理的行为。我猜,使用SelectedIndexChanged事件会提供做数据工作的机会。但该事件上的每个选择/取消触发两次,它并不总是清楚哪些项目应在ListView在这一点上。

This seems to me like pretty ordinary and reasonable behaviour. I guessed that using the SelectedIndexChanged event would offer the opportunities to do the data work. But the event fires twice on every selection/deselection and it's not always clear which items should be updated in the listview at which point.

在code测试什么样的选择/取消才刚刚发生,并因此决定应采取什么行动​​开始变得很长,我只是想知道,如果我做的事情太复杂

The code for testing what kind of "selection/deselection" has just taken place and decide what action should thus be taken is starting to get quite long and I'm just wondering if I'm making things too complicated.

所以:


  • 是否有其他事件,我可以用它来实现我的目标的功能?或

  • 有一些关于SelectedIndexChanged事件,我不知道,这将有助于该方案决定它应该是在任何给定点在做什么?或

  • 我是不是要对这个错误的方式?

任何建议,甚至是那些关于我的重新设计形式是最欢迎的。

Any suggestions, even ones about redesigning my form would be most welcome.

编辑:在试图从不同的角度,我改变我的主人哈希表到SortedList的攻击这个问题。问题的其余保持相同。

While trying to attack this problem from a different angle I am changing my master hashtable to a sortedlist. The rest of the problem remains the same.

推荐答案

如果不知道code,它的开始变得很长,我建议如下:

Without knowing the code that's "starting to get quite long" I would suggest the following:

确认Listview1.MultiSelect是假的。
窗体上使用字段(或属性)来跟踪的SelectedItem。
在活动现场,检查新ListView1.Selecteditems [0]!= this.SelectedItem

Make sure Listview1.MultiSelect is false. Use a field (or property) on your Form to track the SelectedItem. In the event, check if the new ListView1.Selecteditems[0] != this.SelectedItem

2部分:看看在DataGridView和数据表作为一种替代解决方案。您的数据听起来很关系和数据的东西有很多的过滤/排序/链接功能。你可以附加一个列表作为数据源,以网格或走远一点和读取数据到数据表。

Part 2: Take a look at the DataGridView and DataTables as an alternative solution. Your data sounds quite "relational" and the Data stuff has a lot of Filtering/Sorting/Linking functionality. You could attach a List as DataSource to a Grid or go a bit further and read your data into DataTables.

这篇关于我失去了我的ListView选择事件处理的东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆