473,387 Members | 1,374 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,387 software developers and data experts.

How can i drag a datarow from a datagrid to other control?

How can i drag a datarow from a datagrid to a other control?
e.g.
Drag a datarow from a datagrid to a TextBox,Then display one colnumn' value
of the datarow .
Or Drag a cell's value to a controll and display/handle the value in the
other controll.
Thanks in advance.
Nov 15 '05 #1
3 2734
Hi,

When the drag operation begins, retrieve the underlying DataRow (there was a
recent thread in the windowsforms.controls newsgroup where I have given an
example on how to do that). Then extract the data from the data row and add
a data object being dragged (you can probably determine the column index for
the cell being dragged and add the plain cell text as the data object).

The destinatation object, if it can accept the data being dragged, will
respond accordingly to the drop operation.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"NewSun" <li*****@163.net> wrote in message
news:u4**************@tk2msftngp13.phx.gbl...
How can i drag a datarow from a datagrid to a other control?
e.g.
Drag a datarow from a datagrid to a TextBox,Then display one colnumn' value of the datarow .
Or Drag a cell's value to a controll and display/handle the value in the
other controll.
Thanks in advance.


Nov 15 '05 #2
Thank you for your kind answer
I could get the "current" data row .
grdDir is inherited from the class defined by me .I add a method called
GetCurrentRow.
The code can run into grdDir_MouseDown, and can get the "current" data
row .
But the code can not run into tbID_DragEnter or tbID_DragDrop.
Here is my code:
private void grdDir_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
DataRow pDataRow = grdDir.GetCurrentRow();
if(pDataRow != null)
{

grdDir.DoDragDrop(pDataRow["ModuelID"].ToString(),DragDropEffects.Move);
}
}
}

private void tbID_DragEnter(object sender,
System.Windows.Forms.DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
e.Effect = DragDropEffects.Move;
else
e.Effect = DragDropEffects.None;
}
private void tbID_DragDrop(object sender,
System.Windows.Forms.DragEventArgs e)
{
tbID.Text = e.Data.GetData(DataFormats.Text).ToString();
}
Nov 15 '05 #3
Dumb safety suggestion: ensure the TextBox's AllowDrop property is set to
"true".

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"NewSun" <li*****@163.net> wrote in message
news:ed**************@TK2MSFTNGP09.phx.gbl...
Thank you for your kind answer
I could get the "current" data row .
grdDir is inherited from the class defined by me .I add a method called GetCurrentRow.
The code can run into grdDir_MouseDown, and can get the "current" data
row .
But the code can not run into tbID_DragEnter or tbID_DragDrop.
Here is my code:
private void grdDir_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
DataRow pDataRow = grdDir.GetCurrentRow();
if(pDataRow != null)
{

grdDir.DoDragDrop(pDataRow["ModuelID"].ToString(),DragDropEffects.Move);
}
}
}

private void tbID_DragEnter(object sender,
System.Windows.Forms.DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
e.Effect = DragDropEffects.Move;
else
e.Effect = DragDropEffects.None;
}
private void tbID_DragDrop(object sender,
System.Windows.Forms.DragEventArgs e)
{
tbID.Text = e.Data.GetData(DataFormats.Text).ToString();
}


Nov 15 '05 #4

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

Similar topics

5
by: Clyde | last post by:
I am trying to implement the user feedback provided by Windows Explorer when draggng a filename from one place to another. I have the drag and drop action worked out but have had no luck in...
3
by: Ajay Krishnan Thampi | last post by:
I have a slight problem implementing 'drag and drop' from a datagrid to a tree-view. I have pasted my code below. Someone please advice me on what to do...pretty blur right now. ==code== ...
2
by: Bajgon | last post by:
Hello, I have got a DataGrid and a DataTable, which is its DataSource. I can use DataTable.Rows.Find(key_value) method to locate any row in the DataTable, using values of key column. The...
1
by: Adam Klobukowski | last post by:
Hello I'm trying to do basic drag and drop from DataGrid control. The problem is that after I start DoDragDrop, items in DataGrid will become unselected. I wish them to remian selected. I hav...
4
by: sonu | last post by:
I want to drag rows from one datagrid and drop that rows in other datagrid. when we drop rows into 2nd datagrid the rows will be deleted from first datagrid i want this functionality in...
3
by: Demetri | last post by:
If one were to develop a web server control (web control library), which enhances the datagrid by implementing a class that inherits from the DataGrid class, and give it drag and drop capability. ...
1
by: Ryan Liu | last post by:
Hi, Is there better way to find the DataRow associate with row of a datagrid? Now I put ID column(PK) as a column in a datagrid, and get this cell value of the datagrid current row...
1
by: Kyjan | last post by:
Greetings to all! Whenever you click the mouse button (left) in the DataGrid, all selected rows are instantly unselected and the row you clicked on is selected. The only way to prevent this is...
0
by: Job Lot | last post by:
I have designed a user interface with controls bound to data using Data Source Window. Draging and dropped customer table from Data Source Window created various navigation controls and a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.