且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

列表视图选择问题

更新时间:2023-11-13 11:28:58

我可以想到两种方法:

1.禁用无法使用的节点或
2.在包含树视图的表单中跟踪上次打开的表单,如果用户打开了他不应该打开的表单,则显示一条消息.
There are two ways that I can think of:

1. Disabling the nodes which cannot be used or
2. Keeping track of last opened form in the form containing the tree view and if the user opens a form which he should not, display a message.


如果我错了,请告诉我,但是听起来您有ListView.您单击一个ListViewItem,它将打开一个表单.但是,如果要再次打开该表单,则必须先选择其他项.

我的猜测是您已经钩住了SelectedIndexChanged事件.如果事实真是这样,那么该事件将仅选择更改时.这意味着,因为已经选择了客户",所以再次单击它不会更改选择.

代替使用SelectedIndexChanged,而使用MouseClick事件.然后,首先检查是否选中了一个项目,如果已​​选中,请打开它的窗体.

或者,在SelectedIndexChanged事件处理程序的末尾,运行listView1.SelectedIndices.Clear();.这样可以确保每次单击时都会触发SelectedIndexChanged事件.这也不会为用户显示项目上的突出显示...听起来像您想要的那样.

您在使用SelectedIndexChanged吗?
Tell me if I am wrong, but it sounds like you have a ListView. You click on one ListViewItem and it opens up a form. But if you want to open that form again, you have to select a different item first.

My guess is that you have hooked the SelectedIndexChanged event. If that''s the case, then the event will only fire when the selection changes. This means that because Customer is already selected, clicking it again doesn''t change the selection.

Instead of using SelectedIndexChanged, use the MouseClick event. Then, first check to see if an item is selected, and if it is, open it''s form.

Or, at the end of the SelectedIndexChanged event handler, run listView1.SelectedIndices.Clear();. This will ensure that everytime you go to click, the SelectedIndexChanged event will fire. That will also not show the highlighting on an item for the user...which sounds like what you might want.

Are you using SelectedIndexChanged?