列表框在选择时一直跳到下一条记录 [英] Listbox keeps jumping to next record in line on selection

查看:76
本文介绍了列表框在选择时一直跳到下一条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在处理此代码以重新排列Listbox项目后,我终于开始工作了。现在问题是,当我选择与另一个选项进行比较时,所选项目会自动跳转到下一个项目并选择它。

After working on this code for rearranging Listbox items, I finally got it to work. Problem is now when I go to make a selection for comparing to another selection the selected item automatically jumps to the next item and selects it it.

Private Sub ListBox1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown

        Dim dde1 As DragDropEffects = DoDragDrop(ListBox1.SelectedItem, DragDropEffects.Move)

        dde1 = DragDropEffects.All

    End Sub
    Private Sub ListBox1_DragOver(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragEnter

        e.Effect = DragDropEffects.All
        ListBox1.Items.Remove(ListBox1.SelectedItem)
    End Sub

    Private Sub ListBox1_DragDrop(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragDrop

        If e.Data.GetDataPresent(DataFormats.Text) Then
            e.Effect = DragDropEffects.Move
            ListBox1.SelectedIndex = ListBox1.IndexFromPoint(ListBox1.PointToClient(New Point(e.X, e.Y)))

        End If
        Dim str As String = DirectCast(e.Data.GetData(DataFormats.StringFormat), String)
        ListBox1.Items.Insert(ListBox1.SelectedIndex, str)

    End Sub
<pre> 

I want to be able to select items without it jumping

What I have tried:

Thought that originally I set the remove from listbox in the wrong portion of the code, but that wasn't the problem. Tried to see if maybe the index portion was throwing it off, but I didn't get anywhere with that.

推荐答案

如果不明显这段代码是否有罪。你确定问题出现在代码的这一部分吗?



我会启动调试器,然后我会跟踪事件以缩小研究范围并最终确定哪一个是有罪的。

或者,知道选择更改后,我会在可以执行此操作的行上放置断点并进行试用,直到找到违规代码的位置。



你应该学会尽快使用调试器,这是一个令人难以置信的学习工具。而不是猜测你的代码在做什么,现在是时候看到你的代码正在执行并确保它能达到预期的效果。



Debugger - 维基百科,免费的百科全书 [ ^ ]

掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]

调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。

调试器中没有魔法,它没有找到bug,它只是帮助你。当代码没有达到预期的效果时,你就会接近一个错误。
Not obvious if this code is guilty or not. Are you sure the problem is in this part of code ?

I would launch the debugger, then I would track events to narrow the research and eventually identify which one is guilty.
Or, knowing that the selection change, I would put breakpoints on lines that can do it and do trial until I spot where is offending code.

You should learn to use the debugger as soon as possible, it is an incredible learning tool. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.


这篇关于列表框在选择时一直跳到下一条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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