PC Review


Reply
Thread Tools Rate Thread

CheckedBoxList DRAG N DROP and SINGLE CLICK problem

 
 
Holysmoke
Guest
Posts: n/a
 
      27th Mar 2009
Hi All,

I am trying to do drag n drop effect from the values of the checkedboxlist
to a textbox and the code works fine as expected. But the checkedboxlist
loses it characteristics ie single click on the check box of the item.

I have written a mousedown event on the checkedboxlist for drag n drop
effect and it prevents the single click event of the checkbox item. How can I
overcome this problem?

TIA,
Holy

Here is my code,

Please create a new form named form1 and add a textbox and checkedboxlist
into the form and paste this code


Private Sub CheckedListBox1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles CheckedListBox1.MouseDown
CheckedListBox1.DoDragDrop(CheckedListBox1.SelectedItem,
DragDropEffects.Copy)
End Sub

Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop

If e.Data.GetDataPresent(GetType(System.String)) Then
TextBox1.Text = DirectCast(e.Data.GetData(GetType(String)),
String)
End If
TextBox1.BorderStyle = BorderStyle.Fixed3D
End Sub

Private Sub TextBox1_DragEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter
If e.Data.GetDataPresent(GetType(System.String)) Then
e.Effect = DragDropEffects.Copy
TextBox1.BorderStyle = BorderStyle.FixedSingle
End If
End Sub


 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      27th Mar 2009
"Holysmoke" <(E-Mail Removed)> schrieb
> Hi All,
>
> I am trying to do drag n drop effect from the values of the checkedboxlist
> to a textbox and the code works fine as expected. But the checkedboxlist
> loses it characteristics ie single click on the check box of the item.
>
> I have written a mousedown event on the checkedboxlist for drag n drop
> effect and it prevents the single click event of the checkbox item. How
> can I
> overcome this problem?
>
> TIA,
> Holy
>
> Here is my code,
>
> Please create a new form named form1 and add a textbox and checkedboxlist
> into the form and paste this code
>
>
> Private Sub CheckedListBox1_MouseDown(ByVal sender As Object, ByVal e
> As
> System.Windows.Forms.MouseEventArgs) Handles CheckedListBox1.MouseDown
> CheckedListBox1.DoDragDrop(CheckedListBox1.SelectedItem,
> DragDropEffects.Copy)
> End Sub
>
> Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As
> System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop
>
> If e.Data.GetDataPresent(GetType(System.String)) Then
> TextBox1.Text = DirectCast(e.Data.GetData(GetType(String)),
> String)
> End If
> TextBox1.BorderStyle = BorderStyle.Fixed3D
> End Sub
>
> Private Sub TextBox1_DragEnter(ByVal sender As Object, ByVal e As
> System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter
> If e.Data.GetDataPresent(GetType(System.String)) Then
> e.Effect = DragDropEffects.Copy
> TextBox1.BorderStyle = BorderStyle.FixedSingle
> End If
> End Sub



Only set a flag (Boolean) in MouseDown. Start dragging in the MouseMove
event but only if the flag is set (and reset the flag). Also reset the flag
in MouseUp. You should also limit these action to the left mouse button.


Armin

 
Reply With Quote
 
Holysmoke
Guest
Posts: n/a
 
      30th Mar 2009
TAN Q. It works like a charm.

"Holysmoke" wrote:

> Hi All,
>
> I am trying to do drag n drop effect from the values of the checkedboxlist
> to a textbox and the code works fine as expected. But the checkedboxlist
> loses it characteristics ie single click on the check box of the item.
>
> I have written a mousedown event on the checkedboxlist for drag n drop
> effect and it prevents the single click event of the checkbox item. How can I
> overcome this problem?
>
> TIA,
> Holy
>
> Here is my code,
>
> Please create a new form named form1 and add a textbox and checkedboxlist
> into the form and paste this code
>
>
> Private Sub CheckedListBox1_MouseDown(ByVal sender As Object, ByVal e As
> System.Windows.Forms.MouseEventArgs) Handles CheckedListBox1.MouseDown
> CheckedListBox1.DoDragDrop(CheckedListBox1.SelectedItem,
> DragDropEffects.Copy)
> End Sub
>
> Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As
> System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop
>
> If e.Data.GetDataPresent(GetType(System.String)) Then
> TextBox1.Text = DirectCast(e.Data.GetData(GetType(String)),
> String)
> End If
> TextBox1.BorderStyle = BorderStyle.Fixed3D
> End Sub
>
> Private Sub TextBox1_DragEnter(ByVal sender As Object, ByVal e As
> System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter
> If e.Data.GetDataPresent(GetType(System.String)) Then
> e.Effect = DragDropEffects.Copy
> TextBox1.BorderStyle = BorderStyle.FixedSingle
> End If
> End Sub
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with Drag-and-drop works for muilti rows but not single =?Utf-8?B?UHVjY2E=?= Microsoft C# .NET 0 2nd May 2007 12:45 AM
Help with double-click and drag-drop Bill Angus Microsoft Dot NET Framework Forms 7 23rd Nov 2006 02:36 PM
Right-click Drag and Drop problems Trond Ruud Windows XP Help 5 22nd Nov 2004 04:30 PM
Right-click Drag and Drop won't work Trond Ruud Windows XP General 2 17th Jun 2004 06:08 PM
Drag & Drop can't work with Click????? Mike Chan Microsoft VB .NET 1 20th Jan 2004 08:10 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:13 PM.