Click here to Skip to main content
15,910,277 members
Home / Discussions / C#
   

C#

 
GeneralRestarting a service Pin
Mauricio Ritter18-Apr-05 4:38
Mauricio Ritter18-Apr-05 4:38 
GeneralRe: Restarting a service Pin
Dave Kreskowiak18-Apr-05 5:24
mveDave Kreskowiak18-Apr-05 5:24 
GeneralRe: Restarting a service Pin
Mauricio Ritter18-Apr-05 6:38
Mauricio Ritter18-Apr-05 6:38 
GeneralRe: Restarting a service Pin
Dave Kreskowiak18-Apr-05 7:33
mveDave Kreskowiak18-Apr-05 7:33 
GeneralRe: Restarting a service Pin
Alex Korchemniy18-Apr-05 9:05
Alex Korchemniy18-Apr-05 9:05 
QuestionHow to handle Scroll Bar events for word in c#? Pin
18-Apr-05 3:56
suss18-Apr-05 3:56 
GeneralReadFile, Accept methods in C#.net Pin
Babarsaeed18-Apr-05 3:39
Babarsaeed18-Apr-05 3:39 
GeneralHelp--Drag Drop Event Sometimes not work and Some times it works Pin
M Umair tariq18-Apr-05 1:59
M Umair tariq18-Apr-05 1:59 
Here is the code for my problem.Copy paste it and then try to drag item from listView to TreeView.sometimes code works and soem times it does not works at all.Please help

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Drag_n_Drop_ListView_To_TreeView
{
///
/// Summary description for Form1.
///

public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TreeView treeView1;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.Label label1;
///
/// Required designer variable.
///

private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem("Item1");
System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem("Item2");
System.Windows.Forms.ListViewItem listViewItem3 = new System.Windows.Forms.ListViewItem("Item3");
System.Windows.Forms.ListViewItem listViewItem4 = new System.Windows.Forms.ListViewItem("Item4");
this.treeView1 = new System.Windows.Forms.TreeView();
this.listView1 = new System.Windows.Forms.ListView();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// treeView1
//
this.treeView1.AllowDrop = true;
this.treeView1.HideSelection = false;
this.treeView1.ImageIndex = -1;
this.treeView1.Location = new System.Drawing.Point(0, 0);
this.treeView1.Name = "treeView1";
this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("Node0", new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("Node3", new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("Node4", new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("Node5")})}),
new System.Windows.Forms.TreeNode("Node6")}),
new System.Windows.Forms.TreeNode("Node1", new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("Node7", new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("Node8", new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("Node9", new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("Node10")})})})}),
new System.Windows.Forms.TreeNode("Node2"),
new System.Windows.Forms.TreeNode("Node11", new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("Node12", new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("Node13", new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("Node14", new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("Node15")})}),
new System.Windows.Forms.TreeNode("Node16", new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("Node17", new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("Node18")})})})})});
this.treeView1.SelectedImageIndex = -1;
this.treeView1.Size = new System.Drawing.Size(168, 304);
this.treeView1.TabIndex = 0;
//
// listView1
//
this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
listViewItem1,
listViewItem2,
listViewItem3,
listViewItem4});
this.listView1.Location = new System.Drawing.Point(168, 0);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(352, 304);
this.listView1.TabIndex = 1;
this.listView1.View = System.Windows.Forms.View.List;
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 312);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(208, 16);
this.label1.TabIndex = 2;
this.label1.Text = "Drag n Drop From ListView To TreeView";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(520, 333);
this.Controls.Add(this.label1);
this.Controls.Add(this.listView1);
this.Controls.Add(this.treeView1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);

}
#endregion

///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
listView1.ItemDrag+=new ItemDragEventHandler(listView1_ItemDrag);
treeView1.DragEnter+=new DragEventHandler(treeView1_DragEnter);
treeView1.DragDrop+=new DragEventHandler(treeView1_DragDrop);
}

private void listView1_ItemDrag(object sender, ItemDragEventArgs e)
{
string strItem = e.Item.ToString();
// Start the Drag Operation
DoDragDrop(strItem, DragDropEffects.Copy | DragDropEffects.Move);
}

private void treeView1_DragEnter(object sender, DragEventArgs e)
{
// Handle the Drag effect when the listbox is entered

if (e.Data.GetDataPresent(DataFormats.Text))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}

private void treeView1_DragDrop(object sender, DragEventArgs e)
{

// Get the Data from the DragEventArguement
string dummy = "hello";
string s = (string)e.Data.GetData(dummy.GetType());
// Parse out the type information
s = s.Substring(s.IndexOf(":") + 1).Trim();
System.Drawing.Point p = new Point(e.X,e.Y);
TreeNode selectedNode = treeView1.GetNodeAt(e.X,e.Y);
// Find the node at this position
TreeNode DropNode = this.treeView1.GetNodeAt(p);
// if the node exists, insert a new node with the dropped string
// into the second tree
if (DropNode != null)
{
TreeNode DragNode = new TreeNode(s);
MessageBox.Show(s);
treeView1.Nodes.Insert(DropNode.Index+1, DragNode);
}

}


}
}
Generalrdl in c# Pin
tvprithiv18-Apr-05 1:51
tvprithiv18-Apr-05 1:51 
GeneralRe: rdl in c# Pin
leppie18-Apr-05 3:37
leppie18-Apr-05 3:37 
QuestionHow to Ping? Pin
Alper Camel18-Apr-05 1:31
Alper Camel18-Apr-05 1:31 
AnswerRe: How to Ping? Pin
Colin Angus Mackay18-Apr-05 1:38
Colin Angus Mackay18-Apr-05 1:38 
GeneralRe: How to Ping? Pin
Alper Camel18-Apr-05 1:44
Alper Camel18-Apr-05 1:44 
GeneralRe: How to Ping? Pin
Dave Kreskowiak18-Apr-05 4:57
mveDave Kreskowiak18-Apr-05 4:57 
GeneralRe: How to Ping? Pin
Anonymous18-Apr-05 21:14
Anonymous18-Apr-05 21:14 
GeneralRe: How to Ping? Pin
Dave Kreskowiak19-Apr-05 2:21
mveDave Kreskowiak19-Apr-05 2:21 
GeneralRe: How to Ping? Pin
Alper Camel19-Apr-05 4:13
Alper Camel19-Apr-05 4:13 
GeneralRe: How to Ping? Pin
Dave Kreskowiak19-Apr-05 14:59
mveDave Kreskowiak19-Apr-05 14:59 
GeneralAttaching custom methods Pin
Enishi18-Apr-05 1:29
Enishi18-Apr-05 1:29 
GeneralRe: Attaching custom methods Pin
MoustafaS18-Apr-05 2:42
MoustafaS18-Apr-05 2:42 
GeneralRe: Attaching custom methods Pin
Sebastian Schneider18-Apr-05 3:09
Sebastian Schneider18-Apr-05 3:09 
GeneralRe: Attaching custom methods Pin
Enishi18-Apr-05 21:38
Enishi18-Apr-05 21:38 
GeneralNetworking Pin
Alper Camel18-Apr-05 1:12
Alper Camel18-Apr-05 1:12 
GeneralRe: Networking Pin
Dave Kreskowiak18-Apr-05 4:51
mveDave Kreskowiak18-Apr-05 4:51 
GeneralRe: Networking Pin
BambooMoon18-Apr-05 5:46
BambooMoon18-Apr-05 5:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.