pinkybaby

Hi, does anyone know to write the C# codes on how to create a double click event for ListView to delete/remove the item that i select from ListView control


Re: Windows Forms General question of DoubleClick on ListView in C#,need help!!!

Harsimrat

If you are using the Visual Studio Compiler, go to List View properties on the right hand side and there is a double click property. From there you can have that.

Also try clicking on your ListView Control twice and it should do that for you in the Code.

Manually, it should go in the designer code as well as C# code file.Should look something like this on both places.

// In the Designer

this.listView2.DoubleClick += new System.EventHandler(this.listView2_DoubleClick);

// In the CS Code file

private void listView2_DoubleClick(object sender, System.EventArgs e)

{

}

Hope this helps.

Thanks,

Harsimrat





Re: Windows Forms General question of DoubleClick on ListView in C#,need help!!!

sunni05

Hi Harsimrat,

Thank you for your codes, by the way,i am using Visual Studio .NET 2.0 Compact Framework to develop my application. In this VS2005 , i couldn't get this in the designer "this.listView2.DoubleClick += new System.EventHandler(this.listView2_DoubleClick);" . It doesn't provide DoubleClick for ListView in VS2005.






Re: Windows Forms General question of DoubleClick on ListView in C#,need help!!!

Harsimrat

I don't have enough knowledge about .NET Compact Framework, but try posting your question here

http://forums.microsoft.com/MSDN/ShowForum.aspx ForumID=33&SiteID=1

its .NET Compact Framework forum...





Re: Windows Forms General question of DoubleClick on ListView in C#,need help!!!

RizwanSharp

Edit:

Very Good Aproach Here:

http://msdn2.microsoft.com/en-us/library/ms172533.aspx

Best Regards,

Rizwan aka RizwanSharp

There is no double click event in compact framework. You can do a trick by using a Timer.

See this Post:

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=732678&SiteID=1

I hope this will help.

Best Regards,

Rizwan aka RizwanSharp






Re: Windows Forms General question of DoubleClick on ListView in C#,need help!!!

sunni05

Hi Harsimrat,

Thank You for your suggestion. I will look for it.






Re: Windows Forms General question of DoubleClick on ListView in C#,need help!!!

Harsimrat

Thats a really nice article....



Re: Windows Forms General question of DoubleClick on ListView in C#,need help!!!

sunni05

Hi RizwanSharp,
Thank you for your ideas to share it with me. By the way, i found the double click event in compact framework was replaced by ItemActivate event.Anyway, thanks for your ideas and your help





Re: Windows Forms General question of DoubleClick on ListView in C#,need help!!!

Magnus_B

The following event methods and Timer should do it. It detects the second click (was made for DateTimePicker which doesn't implement the Click or DoubleClick events. It is not 100% conserning the time of detection, but you may figure that out yourself. It does detect the second click:

/* The events */

void DTTime_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (dblclickTimer.Enabled)
{
txtSecondClick.Text = "You clicked twice within 1 second";
}
}

void DTTime_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (!dblclickTimer.Enabled)
{
txtTimerDone.Text = "";
dblclickTimer.Enabled = true;
dblclickTimer.Start();
txtFirstClick.Text = "You clicked and started the timer";
}
}

private int clickCounter = 100;
private void dblclickTimer_Tick(object sender, EventArgs e)
{
while (dblclickTimer.Enabled)
{
clickCounter += dblclickTimer.Interval; //Interval = 100
if (clickCounter == 1000)
{
dblclickTimer.Enabled = false;
txtTimerDone.Text = "The timer has ended at 1 second";
clickCounter = 100;
txtFirstClick.Text = "";
txtSecondClick.Text = "";
}
}
}

/* Implementing the events */

this.DTTime.MouseDown += new System.Windows.Forms.MouseEventHandler(this.DTTime_MouseDown);
this.DTTime.MouseUp += new System.Windows.Forms.MouseEventHandler(this.DTTime_MouseUp);






Re: Windows Forms General question of DoubleClick on ListView in C#,need help!!!

sunni05

Hi Magnus_B,

Thank you for your nice and good idea, i did found the solution. Again thanks to all and your help. =P