单击事件屏蔽双击事件的问题,请教高手!!

wangleihefei7819 2003-03-17 05:21:54
我用listview控件显示数据,需要单击某一行或双击某一行然后分别进行相应处理,我在程序中分别写了响应单击某一行和双击某一行事件的代码,但程序执行时,单击事件屏蔽双击事件,无论怎样点击,程序只响应单击事件,双击事件不触发,因为领导要求程序要能够实现单击和双击事件,所以非常急!请赐教!
...全文
132 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Bob 2003-03-17
  • 打赏
  • 举报
回复
我想没有其它可能吧:)
wangleihefei7819 2003-03-17
  • 打赏
  • 举报
回复
还有回答的吗?
ismezy2002 2003-03-17
  • 打赏
  • 举报
回复
应该不会是单击屏敝了双击,可能是你在单击事件中的代码影响了当前的状态,如弹出一个对话框使当前窗口失去焦点等

--------------纯属猜测------------ :)
Bob 2003-03-17
  • 打赏
  • 举报
回复
如果你在Click事件处理函数中做了一些让listview失去焦点的事,如MessageBox之类的,那么,DoubleClick事件是无法发生的,看看下面的程序,就可以实现两者兼容:

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

namespace WindowsApplication1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.Label label1;
private System.ComponentModel.IContainer components;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] {
"222222"}, -1, System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))));
System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem(new string[] {
"111111"}, -1, System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))));
this.listView1 = new System.Windows.Forms.ListView();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// listView1
//
this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
listViewItem1,
listViewItem2});
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(240, 180);
this.listView1.TabIndex = 0;
this.listView1.Click += new System.EventHandler(this.listView1_Click);
this.listView1.DoubleClick += new System.EventHandler(this.listView1_DoubleClick);
//
// label1
//
this.label1.Location = new System.Drawing.Point(15, 200);
this.label1.Name = "label1";
this.label1.TabIndex = 1;
this.label1.Text = "label1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(347, 253);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label1,
this.listView1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void listView1_Click(object sender, System.EventArgs e)
{
label1.Text = "Click";
}

private void listView1_DoubleClick(object sender, System.EventArgs e)
{
MessageBox.Show("DoubleClick");
}
}
}
myqiao 2003-03-17
  • 打赏
  • 举报
回复
gzing....

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧