我用了下面这事件,但事件不响应,大概是因为 datagrid中有TAB事件:private void dgSearch_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyValue == 9)
{
this.dgSearch.Select(dgSearch.CurrentRowIndex + 1);
}
}
{
if(e.KeyValue == 9)
{
this.dgSearch.Select(dgSearch.CurrentRowIndex + 1);
}
}
解决方案 »
- 关于treeView1,绑写数据库,成为树形结构
- C#生成多个指定名称的变量?????
- [WEB开发]100分求解树型控件TreeView单击绑定问题??
- 如何数据库连接放到统一的位置?
- 多个UI线程如何实现队列?
- 关于调试问题,希望高手帮忙。。。
- 跪求一个web form中的时间控件,不要象.net中的那么大的一个日历控件,如果有代码请发给我一份,以及怎么在.net C#中调用,谢谢,分100在
- 短信平台控制
- 请教:怎样用C#实现网页上的倒计时时钟?
- 请问如何能把从数据库中查询的结果集保存成excel或word形式?
- 使用了wrapper assembly 引用了COM组件的系统,发布后还要在目标机器上注册COM吗?
- 求《Applied Microsoft .Net Framework Programming》和《programming windows with c# 》这两本书
zzwsz
谢谢你,我来试试!
希望其他朋友能提供方法!
你能说具体点吗,这个方法我还不会写呢,从未写过此方法,谢谢!我也在看
using System.Drawing;
using System.Data;
using System.Windows.Forms;namespace DataGridEX{
public delegate void DeleteKey(ref System.Windows.Forms.Message msg);
/// <summary>
/// UserControl1 的摘要说明。
/// </summary>
public class DataGridEX : System.Windows.Forms.DataGrid
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public DataGridEX()
{
// 该调用是 Windows.Forms 窗体设计器所必需的。
InitializeComponent(); // TODO: 在 InitializeComponent 调用后添加任何初始化 } /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
} #region Component Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
//
// UserControl1
//
this.Name = "DataGridEX";
}
#endregion public override bool PreProcessMessage(ref System.Windows.Forms.Message msg)
{
// if(msg.Msg==256)
// {
// System.Console.Write("\n"+msg.ToString ());
// this.Select(this.CurrentRowIndex+1);
// return(true);
// }
// else
// {
// base.WndProc(ref msg);
// return(false);
// }
if(msg.WParam.ToInt32()==46)
{
System.Console.WriteLine(msg.WParam.ToInt32().ToString()+"is catch!");
//base.WndProc(ref m);
this.DataGrid_DeleteKey(ref msg);
return(true);
}
else
{
base.PreProcessMessage(ref msg);
return(false); }
}
public event DeleteKey DataGrid_DeleteKey;
}
}
还是没实现,不太清楚你这方法的用处,能再讲一下吗,不好意思了!
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;namespace DataGridEX{
//public delegate void TabKey(ref System.Windows.Forms.Message msg);
/// <summary>
/// UserControl1 的摘要说明。
/// </summary>
public class DataGridEX : System.Windows.Forms.DataGrid
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public DataGridEX()
{
// 该调用是 Windows.Forms 窗体设计器所必需的。
InitializeComponent(); // TODO: 在 InitializeComponent 调用后添加任何初始化 } /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
} #region Component Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
//
// UserControl1
//
this.Name = "DataGridEX";
}
#endregion
//public event TabKey DataGrid_TabKey;//定义TAB键的事件
public override bool PreProcessMessage(ref System.Windows.Forms.Message msg)//重写PreProcessMessage
{
System.Console.Write("\n"+msg.ToString ());
if(msg.Msg==0x100&&msg.WParam.ToInt32 ()==9&&msg.LParam.ToInt32()==983041)//判断是否为TAB键
{
this.UnSelect(this.CurrentRowIndex);
this.Select(this.CurrentRowIndex+1);
this.CurrentRowIndex++;
this.Refresh();
return(true);
}
else
{
return(false);//表示未作处理
}
}
}
}
将以上代码编译成控件dll,然后在你的工程在添加引用,在并有DataGridEX代替DataGrid即可