473,405 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

(New) DataGridView Question

If I click down on a control on a form and then drag and release on a
datagridview, how can I tell which cell the release occured over?

Jul 12 '06 #1
2 1882

jo*********@topscene.com wrote:
If I click down on a control on a form and then drag and release on a
datagridview, how can I tell which cell the release occured over?
When the drag is dropped, the DGV will receive a DragDrop event
containing the screen coordinates of the drop point. Convert these to
client coordinates with PointToClient, then use the HitTest method to
workout where the drop was. Sample code:

Private Sub DataGridView1_DragDrop(ByVal sender As Object, ByVal e
As System.Windows.Forms.DragEventArgs) Handles DataGridView1.DragDrop
Dim dropPointScreen As Point = New Point(e.X, e.Y)
Dim dropPointClient As Point =
DataGridView1.PointToClient(dropPointScreen)
Dim hitTest As DataGridView.HitTestInfo = _
DataGridView1.HitTest(dropPointClient.X, dropPointClient.Y)

MsgBox("Dropped on row " & hitTest.RowIndex.ToString & _
", column " & hitTest.ColumnIndex.ToString)
End Sub

--
Larry Lard
Replies to group please
When starting a new topic, please mention which version of VB/C# you
are using

Jul 13 '06 #2

Larry Lard wrote:
jo*********@topscene.com wrote:
If I click down on a control on a form and then drag and release on a
datagridview, how can I tell which cell the release occured over?

When the drag is dropped, the DGV will receive a DragDrop event
containing the screen coordinates of the drop point. Convert these to
client coordinates with PointToClient, then use the HitTest method to
workout where the drop was. Sample code:

Private Sub DataGridView1_DragDrop(ByVal sender As Object, ByVal e
As System.Windows.Forms.DragEventArgs) Handles DataGridView1.DragDrop
One day I will learn to check which group I am posting to.

public Form1()
{
InitializeComponent();

dataGridView1.AllowDrop = true;
dataGridView1.DragEnter += new
DragEventHandler(dataGridView1_DragEnter);
dataGridView1.DragDrop += new
DragEventHandler(dataGridView1_DragDrop);
}

void dataGridView1_DragDrop(object sender, DragEventArgs e)
{
Point dropPointScreen = new Point(e.X, e.Y);
Point dropPointClient =
dataGridView1.PointToClient(dropPointScreen);
DataGridView.HitTestInfo hitTest =
dataGridView1.HitTest(dropPointClient.X,
dropPointClient.Y);

MessageBox.Show("Dropped on row " +
hitTest.RowIndex.ToString() +
", column " +
hitTest.ColumnIndex.ToString());

}

void dataGridView1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
--
Larry Lard
Replies to group please
When starting a new topic, please mention which version of VB/C# you
are using

Jul 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: milk-jam | last post by:
I'm trying to set my datagridview so that the first row will be left blank and to use it as a filtering filed for the datagridview. Until now I was using 2 datagridview the upper one with a header...
0
by: TNSFED | last post by:
I have a dilemma when trying to delete a row from the DataGridView. Here is a sample of my code: private void dgv_EQUPS_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) {...
7
by: Mitchell S. Honnert | last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the DataGridView? If not, is there an easy way to duplicate the DataGridTableStyle's functionality for the DataGridView? Here's...
2
by: michael sorens | last post by:
I have been trying to figure out how to use DataSets, BindingSources, DataGridViews, and XML together, but it is a challenge. I understand how to populate a DataGridView with XML basically as: ...
4
by: craig.wenger | last post by:
I am using a DataGridView to display information stored in classes. I am linking to the information with the Tag property of the DataGridView rows. Unfortunately, whenever I set the Tag property,...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
2
by: Dom | last post by:
I posted this before, no takers. Trying again. Is there anyway to cancel the selection of a new cell in a DataGridView? For example, if the user selects a cell with the control key down, then...
1
nev
by: nev | last post by:
Happy Easter to all! I have a problem with a datagridview. I placed code in a button click event as follows: dim dtt as datatable = dataset.employees.copy dtt.DefaultView.RowFilter = "='" &...
6
by: Miro | last post by:
Sorry for the cross post. I am stuck. I have a datagridview for poker rounds. Basically there are 3 columns in this datagridview. "Round" "SmallBlind" "BigBlind" I have an issue when I tab...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.