473,546 Members | 2,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2745
Hi,

When the drag operation begins, retrieve the underlying DataRow (there was a
recent thread in the windowsforms.co ntrols 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.ne t> wrote in message
news:u4******** ******@tk2msftn gp13.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_MouseDow n, 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_MouseDow n(object sender,
System.Windows. Forms.MouseEven tArgs e)
{
if(e.Button == MouseButtons.Le ft)
{
DataRow pDataRow = grdDir.GetCurre ntRow();
if(pDataRow != null)
{

grdDir.DoDragDr op(pDataRow["ModuelID"].ToString(),Dra gDropEffects.Mo ve);
}
}
}

private void tbID_DragEnter( object sender,
System.Windows. Forms.DragEvent Args e)
{
if (e.Data.GetData Present(DataFor mats.Text))
e.Effect = DragDropEffects .Move;
else
e.Effect = DragDropEffects .None;
}
private void tbID_DragDrop(o bject sender,
System.Windows. Forms.DragEvent Args e)
{
tbID.Text = e.Data.GetData( DataFormats.Tex t).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.ne t> wrote in message
news:ed******** ******@TK2MSFTN GP09.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_MouseDow n, 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_MouseDow n(object sender,
System.Windows. Forms.MouseEven tArgs e)
{
if(e.Button == MouseButtons.Le ft)
{
DataRow pDataRow = grdDir.GetCurre ntRow();
if(pDataRow != null)
{

grdDir.DoDragDr op(pDataRow["ModuelID"].ToString(),Dra gDropEffects.Mo ve);
}
}
}

private void tbID_DragEnter( object sender,
System.Windows. Forms.DragEvent Args e)
{
if (e.Data.GetData Present(DataFor mats.Text))
e.Effect = DragDropEffects .Move;
else
e.Effect = DragDropEffects .None;
}
private void tbID_DragDrop(o bject sender,
System.Windows. Forms.DragEvent Args e)
{
tbID.Text = e.Data.GetData( DataFormats.Tex t).ToString();
}


Nov 15 '05 #4

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

Similar topics

5
4943
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 finding how to capture the piece of the screen into a bitmap to simulate the movement. I know this could be done with the Windows API but can't find any...
3
10393
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== using System; using System.Drawing; using System.Collections; using System.ComponentModel;
2
5458
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 result is a DataRow object. How to find and select the current position of this DataRow in the DataGrid control?
1
7976
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 such code: private void dataGrid_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
4
2416
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 web application.
3
1638
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. In other words a re-usable server control that is a datagrid only it allows a user to drag it around the web page. Any suggestions on how to...
1
1551
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 (DataGrid.CurrentRowIndex), then use DataTable.Rows.Find(id) to find the datarow. I feel this way is not generic. Is there better way to find the associated...
1
1156
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 by pressing one of the control keys (Shift or Ctrl). What I want the user to be able to do is to select multiple rows from the DataGrid and just...
0
1437
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 DataGridView control. I am storing cusotmer information along with their image in customer table. I have a separate form for editing new customer information...
0
7507
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7435
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7698
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7947
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7794
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6030
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3492
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1922
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.