trying to do drag drop

Discussion in 'Microsoft VB .NET' started by active, Nov 23, 2003.

  1. active

    active Guest

    Code below.
    Starting to use DragDrop and I get the message that the index is out of
    range when I mouse down and move a little. The box has maybe 10 items and
    I'm selecting one in the middle.

    Second question. In the examples for ListBox they use:
    alstFrom.SelectedItem.Text but when I add a dot after SelectedItem I get
    only the option GetType. Can this be explained??

    Finally. The conversion from VB6 placed ByRef with the first argument. Any
    reason. Seems like ByVal would also work. In fact I think it would work even
    if I wanted to make changes in the listbox. Is ByRef the preferred way.

    Thanks for any insight passed along,
    Cal

    Private Sub MouseMoveHelper(ByRef alstFrom As System.Windows.Forms.ListBox,
    ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
    If e.Button = 0 Or alstFrom.Items.Count < 1 Or mbolDragProhibited Then Exit
    Sub
    Dim tbase As ListBox = DirectCast(sender, ListBox)
    Dim data As New DataObject
    data.SetData(DataFormats.Text, CStr(alstFrom.SelectedItem))
    Dim effect As DragDropEffects = DragDropEffects.Move
    effect = tbase.DoDragDrop(data, effect)
    End Sub
     
    active, Nov 23, 2003
    #1
    1. Advertisements

  2. active wrote:
    > Code below.
    > Starting to use DragDrop and I get the message that the index is out
    > of range when I mouse down and move a little. The box has maybe 10
    > items and I'm selecting one in the middle.

    Put a debug.writeline to send the co-ordinates to the output window. This
    way you will see what you are trying to work with. I have found that the
    screen co-ordinates sometimes need to be converted to the client
    co-ordinates of the control. Using the PointToScreen co-ordinate in the
    RectangleToScreen methods.


    >
    > Second question. In the examples for ListBox they use:
    > alstFrom.SelectedItem.Text but when I add a dot after SelectedItem I
    > get only the option GetType. Can this be explained??

    Because you have not instantiated it as a New type of LitBoxItem. It
    doesent know at pre run stage what it is. As a matter of course, use OPTION
    STRICT, this will prevent late binding compilation and reduce the number of
    these kinds of errors.

    >
    > Finally. The conversion from VB6 placed ByRef with the first
    > argument. Any reason. Seems like ByVal would also work. In fact I
    > think it would work even if I wanted to make changes in the lis

    tbox.
    > Is ByRef the preferred way.


    It's up to you to use it as appropriate. If you specified ByVal on the VB6
    code, it would translate it the same otherwise it will be byRef as default.

    Regards OHM





    >
    > Thanks for any insight passed along,
    > Cal
    >
    > Private Sub MouseMoveHelper(ByRef alstFrom As
    > System.Windows.Forms.ListBox, ByVal sender As Object, ByVal e As
    > System.Windows.Forms.MouseEventArgs)
    > If e.Button = 0 Or alstFrom.Items.Count < 1 Or mbolDragProhibited
    > Then Exit Sub
    > Dim tbase As ListBox = DirectCast(sender, ListBox)
    > Dim data As New DataObject
    > data.SetData(DataFormats.Text, CStr(alstFrom.SelectedItem))
    > Dim effect As DragDropEffects = DragDropEffects.Move
    > effect = tbase.DoDragDrop(data, effect)
    > End Sub
     
    One Handed Man, Nov 23, 2003
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ramana
    Replies:
    0
    Views:
    665
    Ramana
    Jul 3, 2003
  2. Goldwind

    Drag & Drop

    Goldwind, Aug 31, 2003, in forum: Microsoft VB .NET
    Replies:
    3
    Views:
    252
    Cameron McColl
    Sep 4, 2003
  3. Thomas

    drag-drop from outlook problem

    Thomas, Sep 3, 2003, in forum: Microsoft VB .NET
    Replies:
    3
    Views:
    236
    John Chen
    Sep 4, 2003
  4. Samuel R. Neff
    Replies:
    0
    Views:
    434
    Samuel R. Neff
    Dec 23, 2004
  5. Samuel R. Neff
    Replies:
    3
    Views:
    1,888
    Peter Huang [MSFT]
    Dec 30, 2004
Loading...

Share This Page