Treeview has a function on "Afterselect" worked perfectly but when i implemented drag drop function on the treeview, it required a mousedown action. Now u have to click on the node and then click on the node again to get the afterselect.
How do i make the afterselect function run with just 1 click?
5 3023 cloud255 427
Recognized Expert Contributor
Hi
To clarify if I understand what your code is doing:
1. You have the ability to drag and drop a node - this works fine
2. You also call some code only when the node is clicked - this is not working requires 2 clicks
Is this correct?
Could you also maybe post only the relevant code, please dont dump 400 lines of code unless all the code is relevant to this problem.
If I had to guess I would say that the mouse down event is not firing on the first click, but rather that the DragStart event is being raised.
Correct
After select did work perfectly before i implemented drag & drop.
this is my Drag & Drop code
I've tried putting the after select by Mouse down but then it doesn't work -
private void tvDescriptions_MouseDown(object sender, MouseEventArgs e)
-
{
-
TreeView tree = (TreeView)sender;
-
-
// Get the node underneath the mouse.
-
TreeNode node = tree.GetNodeAt(e.X, e.Y);
-
-
// Start the drag-and-drop operation with a cloned copy of the node.
-
if (node != null)
-
{
-
tree.DoDragDrop(node, DragDropEffects.Copy);
-
}
-
-
-
}
-
-
private void tvDescriptions_DragOver(object sender, DragEventArgs e)
-
{
-
// Get the tree.
-
TreeView tree = (TreeView)sender;
-
-
-
// Drag and drop denied by default.
-
e.Effect = DragDropEffects.None;
-
-
// Is it a valid format?
-
if (e.Data.GetData(typeof(TreeNode)) != null)
-
{
-
// Get the screen point.
-
Point pt = new Point(e.X, e.Y);
-
-
// Convert to a point in the TreeView's coordinate system.
-
pt = tree.PointToClient(pt);
-
-
// Is the mouse over a valid node?
-
TreeNode node = tree.GetNodeAt(pt);
-
if (node != null)
-
{
-
e.Effect = DragDropEffects.Copy;
-
tree.SelectedNode = node;
-
-
}
-
}
-
}
-
-
private void tvDescriptions_DragDrop(object sender, DragEventArgs e)
-
{
-
try
-
{
-
// Get the tree.
-
TreeView tree = (TreeView)sender;
-
-
tree.BeginUpdate();
-
-
// Get the screen point.
-
Point pt = new Point(e.X, e.Y);
-
-
// Convert to a point in the TreeView's coordinate system.
-
pt = tree.PointToClient(pt);
-
-
// Get the node underneath the mouse.
-
TreeNode node = tree.GetNodeAt(pt);
-
-
TreeNode childNode = (TreeNode)e.Data.GetData(typeof(TreeNode));
-
-
// Remove this node
-
tree.Nodes.Remove(childNode);
-
-
// Add the node to the new parent
-
node.Nodes.Add(childNode);
-
-
// Show the newly added node if it is not already visible.
-
node.Expand();
-
-
tree.EndUpdate();
-
-
UpdateDB(childNode.Tag, node.Tag);
-
}
-
catch (Exception ex)
-
{
-
MessageBox.Show("Error: " + ex.Message);
-
}
-
}
-
private void UpdateDB(object Id, object parentId)
-
{
-
OleDbConnection mConn = new OleDbConnection(strCon);
-
-
mConn.Open();
-
-
string UpdateStr = @"UPDATE [qx_AssetDescription] SET ads__ads_id = @parentId where ads__ID = @Id";
-
-
OleDbCommand myCmd = mConn.CreateCommand();
-
myCmd.CommandText = UpdateStr;
-
try
-
{
-
myCmd.Parameters.AddWithValue("parentId", parentId);
-
myCmd.Parameters.AddWithValue("Id", Id);
-
-
myCmd.ExecuteNonQuery();
-
//MessageBox.Show("Data added to database");
-
-
}
-
catch (Exception ed)
-
{
-
MessageBox.Show("Error: " + ed.Message, "Error");
-
}
-
finally
-
{
-
myCmd.Dispose();
-
mConn.Close();
-
mConn.Dispose();
-
-
-
}
-
-
}
-
and here is my after select code -
-
string ConnString = Properties.Settings.Default.GriffenConnectionString.ToString();
-
-
OleDbConnection Conn = new OleDbConnection(ConnString);
-
int ParentID = 0;
-
-
LoadDescBoxes();
-
-
string sql = "";
-
DataSet dsFillDesc = new DataSet();
-
string ChkTicked = "";
-
-
try
-
{
-
sql = "Select * from qx_AssetDescription Where ADS__ID = " + tvDescriptions.SelectedNode.Tag.ToString();
-
OleDbDataAdapter daDescFill = new OleDbDataAdapter(sql.ToString(), Conn);
-
daDescFill.Fill(dsFillDesc, "qx_AssetDescription");
-
-
if (dsFillDesc != null)
-
{
-
txtDescShort.Text = Convert.ToString(dsFillDesc.Tables["qx_AssetDescription"].Rows[0]["ADS__SHORT"]);
-
txtDescLong.Text = Convert.ToString(dsFillDesc.Tables["qx_AssetDescription"].Rows[0]["ADS__LONG"]);
-
ChkTicked = Convert.ToString(dsFillDesc.Tables["qx_AssetDescription"].Rows[0]["ADS__Common"]);
-
cboDescParent.SelectedValue = Convert.ToInt32(dsFillDesc.Tables["qx_AssetDescription"].Rows[0]["ADS__ADS_ID"].ToString());
-
-
if (ChkTicked == "True")
-
{
-
chkDescCommon.Checked = true;
-
}
-
else
-
{
-
chkDescCommon.Checked = false;
-
}
-
-
if (dsFillDesc.Tables["qx_AssetDescription"].Rows[0]["ADS__ADS_ID"].ToString() == "0")
-
{
-
cboDescParent.Visible = false;
-
chkDescSelRoot.Checked = true;
-
lblDescParent.Visible = false;
-
}
-
else
-
{
-
ParentID = Convert.ToInt32(dsFillDesc.Tables["qx_AssetDescription"].Rows[0]["ADS__ADS_ID"].ToString());
-
cboDescParent.Visible = true;
-
chkDescSelRoot.Checked = false;
-
lblDescParent.Visible = true;
-
}
-
}
-
}
-
-
catch (Exception ex)
-
{
-
MessageBox.Show(ex.Message.ToString());
-
}
-
finally
-
{
-
dsFillDesc.Clear();
-
dsFillDesc.Dispose();
-
Conn.Close();
-
txtDescShort.Visible = true;
-
txtDescLong.Visible = true;
-
chkDescCommon.Visible = true;
-
chkDescSelRoot.Visible = true;
-
btnDescriptionCancel.Visible = false;
-
lblDescLong.Visible = true;
-
lblDescription.Visible = true;
-
lblDescShort.Visible = true;
-
btnDescriptionSubmit.Visible = false;
-
btnDescriptionUpdate.Enabled = true;
-
btnDescriptionDelete.Enabled = true;
-
}
-
}
-
tlhintoq 3,525
Recognized Expert Specialist
It sounds like "afterselect" still works fine. After all it is working when you just click on a node. Dropping onto a node just isn't a selection so it doesn't fire the event.
You could call the method used from "AfterSelect" at the end of the DragDrop operation. You already know the node since it just received the Drop. (Or initiated the drag. I'm not sure which node you want selected at the end of DnD operation) But use that node as the Object sender parameter when calling the AfterSelect method
cloud255 427
Recognized Expert Contributor
Another solution would be to check which mouse button was pressed in the MouseDown event handler. Then you could say that if the user used the left mouse button, select the node. If the right mouse button was used then start the DragDrop operation.
Thanx for all the help guys, heres how i fixed it -
TreeView tree = (TreeView)sender;
-
-
// Get the node underneath the mouse.
-
TreeNode node = tree.GetNodeAt(e.X, e.Y);
-
-
tvDescriptions.SelectedNode = node;
-
-
if (MouseButtons.Right.Equals(MouseButtons))
-
{
-
// Start the drag-and-drop operation with a cloned copy of the node.
-
if (node != null)
-
{
-
tree.DoDragDrop(node, DragDropEffects.Copy);
-
}
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Ian Powell |
last post by:
Hi
I've got objects in an sorted ArrayList like:
P:\
P:\\DOCS
P:\\i386
P:\\i386\ASMS
P:\\i386\ASMS\1000
P:\\i386\ASMS\1000\MSFT
|
by: Björn Bengtsson |
last post by:
Hello!
I have an urgent problem concerning ASP.NET, ADO.NET, SQL Server, XML and
the TreeView control.
I have two tables; one describing the products and one describing their
relationships. A...
|
by: Karim El Jed |
last post by:
Hi,
I'm trying to expand a special Node of my TreeView from Codebehind.
I have a TreeView on a page for navigating to another site. On the other
tsite here is the same TreeView more precisely a...
|
by: Evan Kontos |
last post by:
I am trying to implement a Treeview w/an XML file and I even copied and
pasted examples from MSDN but can't get them to work. Any suggestions
welcome.
XML File
<TREENODES>
<TREENODE...
|
by: Jeff Beem |
last post by:
I have a class that inherits from TreeView. The treeview has tooltips for
the nodes but they're showing up behind the form. Has anyone seen this? Are
there any known fixes?
Thanks in advance,...
| |
by: christof |
last post by:
I've got a really easy problem, please help me:
There are two pages in one I'm creating a TreeView like that:
TreeView dbTree = new TreeView();
TreeNode dbTreeRoot = new TreeNode("Root");...
|
by: William Sullivan |
last post by:
I desperately want to replace my hand-made ajax treeview with the 2.0
TreeView. The webpage I'm designing uses the postbacks to dynamically fill
the treeview. The reason why I'm doing this is...
|
by: Matt MacDonald |
last post by:
Hi All,
I have a form that displays hierarchical categories in a treeview. Ok so
far so good. What I was to do is have users be able to select a node in the
treeview as part of filling out the...
|
by: Nikron |
last post by:
Hi,
I'm having an issue with the ASP.NET 2.0 Treeview control and persisting
its' state accross requests. My Control is embedded within a master page
and is used for site navigation. My problem...
|
by: bsturg21 |
last post by:
Hello,
I have an app that has a custom treeview which inherits the base
treeview class and I am having a problem with the way the treeview is
being redrawn. Each node in the treeview represents a...
|
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...
| |
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: 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...
|
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...
|
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,...
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |
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 ...
|
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...
| |