By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,633 Members | 1,842 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,633 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.