|
-
Apr 2nd, 2003, 05:38 PM
#1
Thread Starter
Fanatic Member
MouseDown Event Help Needed (DataGrid) [RESOLVED]
Here is the code I use to initiate a Drag and Drop Sequence:
VB Code:
Private Sub DataGrid1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then 'Begins the dragging process
DataGrid1.DragIcon = QuoteForm.ImageList1.ListImages(6).Picture
DataGrid1.Drag vbBeginDrag
IMTextBox.Text = DataGrid1.Text
QuoteForm.dragging = True
QuoteForm.Show
End If
QuoteForm.txtDragValue = DataGrid1.Text & "_MAT"
End Sub
This works great for Drag and Drop BUT if I need to resize the DataGrid Columns, it doesn't work as VB thinks I'm in the middle of a Drag and Drop. Can someone help me change my code so that I can still use it to Drag and Drop BUT still give my users the ability to resize the columns? Thanks, Jeremy
Last edited by JCScoobyRS; Apr 3rd, 2003 at 12:30 PM.
He who listens well, speaks well.
-
Apr 2nd, 2003, 06:20 PM
#2
Frenzied Member
Would this work?- Create a module level variable that tracks if the user is resizing
- In the datagrid Mouse_Down event, set this variable to True
- In the datagrid Mouse_Move event, check the variable and only do drag/drop if it's False
- In the datagrid Mouse_Up event, reset the variable to False
I may be wrong, but I think you can only resize columns in the header, so this code should work:
VB Code:
Private MOUSE_IN_COL_HEADER As Boolean
Private Sub DataGrid1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Y < Int(DataGrid1.Columns.Item(0).Top + 2) Then MOUSE_IN_COL_HEADER = True
End Sub
Private Sub DataGrid1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not MOUSE_IN_COL_HEADER Then
If Button = vbLeftButton Then 'Begins the dragging process
DataGrid1.DragIcon = QuoteForm.ImageList1.ListImages(6).Picture
DataGrid1.Drag vbBeginDrag
IMTextBox.Text = DataGrid1.Text
QuoteForm.dragging = True
QuoteForm.Show
End If
QuoteForm.txtDragValue = DataGrid1.Text & "_MAT"
End If
End Sub
Private Sub DataGrid1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
MOUSE_IN_COL_HEADER = False
End Sub
-
Apr 2nd, 2003, 06:32 PM
#3
Thread Starter
Fanatic Member
Is there anything for the DataGrid similar to "HitText" in the TreeView? If so, I could check to see if it's above Column(0) and if so, don't drag but if not, begin drag. How's that idea? Thanks, Jeremy
He who listens well, speaks well.
-
Apr 2nd, 2003, 06:48 PM
#4
Check out the RowContaining and ColContaining methods. They return the Row/Col given an X/Y coordinate.
FYI: Drag and Drop is usually started in the MouseDown event, not sure why you are starting it every time the mouse is moved.
-
Apr 3rd, 2003, 10:18 AM
#5
Thread Starter
Fanatic Member
You are correct and although there are many ways to get it to work, this way works. After I complete my project, I'll be optimizing it and that is on the list. Thanks, Jeremy
He who listens well, speaks well.
-
Apr 3rd, 2003, 12:30 PM
#6
Thread Starter
Fanatic Member
Bruce,
Once again your expert advice pays off. Here is the working code:
VB Code:
Private Sub DataGrid1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim RowVal As Single
Dim ColVal As Single
RowVal = DataGrid1.RowContaining(y)
ColVal = DataGrid1.ColContaining(x)
If Button = vbLeftButton Then 'Begins the dragging process
If RowVal > 0 And ColVal > 0 Then
DataGrid1.DragIcon = QuoteForm.ImageList1.ListImages(6).Picture
DataGrid1.Drag vbBeginDrag
IMTextBox.Text = DataGrid1.Text
QuoteForm.dragging = True
QuoteForm.Show
End If
End If
QuoteForm.txtDragValue = DataGrid1.Text & "_MAT"
End Sub
Thanks, Jeremy
He who listens well, speaks well.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|