事件的调用问题,请教了~~~

lxuan_025 2009-03-26 04:51:49

在datagridview 控件里,我要实现双击一个 cell 然后 然后弹出一个 界面,显示 那个cell所在列的列名, 用那个 doubleClick了,但是 又不能用e.Cell.Column.Key.ToString(); 来获取列名 很是头痛 。 高手们帮我解决一下吧!


PS(语言 C# 环境 VS2005)
...全文
102 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
lxuan_025 2009-03-27
  • 打赏
  • 举报
回复
还是不行 我用的datagridview 控件不是VS 自带的,里面没有CellDoubleClick 事件。 还有其它什么方法没?
我姓区不姓区 2009-03-26
  • 打赏
  • 举报
回复

private void Form3_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] { new DataColumn("ID", typeof(string)), new DataColumn("Name", typeof(string)), new DataColumn("level1", typeof(int)), new DataColumn("level2", typeof(int)), new DataColumn("level3", typeof(int)), new DataColumn("level4", typeof(int)), new DataColumn("level5", typeof(int)), new DataColumn("level6", typeof(int)) });
dt.Rows.Add("001", "aaa", 1, 0, 0, 0, 0, 0);
dt.Rows.Add("002", "bbb", 1, 1, 0, 0, 0, 0);
dt.Rows.Add("003", "ccc", 1, 2, 0, 0, 0, 0);
dt.Rows.Add("004", "ddd", 2, 0, 0, 0, 0, 0);
dt.Rows.Add("005", "eee", 2, 1, 0, 0, 0, 0);
dt.Rows.Add("006", "fff", 2, 1, 1, 0, 0, 0);
dt.Rows.Add("007", "ggg", 2, 1, 2, 0, 0, 0);
dt.Rows.Add("008", "hhh", 2, 1, 2, 1, 0, 0);
dt.Rows.Add("009", "jjj", 2, 2, 0, 0, 0, 0);
dataGridView1.DataSource = dt;
}

private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
MessageBox.Show("标题:" + (dataGridView1.DataSource as DataTable).Columns[e.ColumnIndex].ColumnName);
MessageBox.Show("单元格中的内容:" + dataGridView1[e.ColumnIndex, e.RowIndex].Value);
}
A海阔天空 2009-03-26
  • 打赏
  • 举报
回复

看下。学习学习
terry 2009-03-26
  • 打赏
  • 举报
回复
注意不错。我也试试。
goodaboy 2009-03-26
  • 打赏
  • 举报
回复
同意楼上的做法``
zzxap 2009-03-26
  • 打赏
  • 举报
回复
设置gridview的datakey

string ID = this.GridView1.DataKeys[e.RowIndex].Values[0].ToString();//获取本行主键
cancerser 2009-03-26
  • 打赏
  • 举报
回复
CellDoubleClick 用这个事件
suosuoyyy 2009-03-26
  • 打赏
  • 举报
回复
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
string colName = dataGridView1.Columns[e.ColumnIndex].Name;
object colData = dataGridView1.CurrentCell.Value;
}

用CellDoubleClick
lxuan_025 2009-03-26
  • 打赏
  • 举报
回复


还是不行~~~~
ztenv 2009-03-26
  • 打赏
  • 举报
回复
dataGridView1.CurrentCell.Value
ztenv 2009-03-26
  • 打赏
  • 举报
回复
dataGridView1.Columns[dataGridView1.CurrentCell.ColumnIndex].HeaderText;
lxuan_025 2009-03-26
  • 打赏
  • 举报
回复
而且不止要列名 还要获取双击的那个cell 里面的 数据
lxuan_025 2009-03-26
  • 打赏
  • 举报
回复


具体怎么做?
xutao888 2009-03-26
  • 打赏
  • 举报
回复
在绑定的时候就把列名写在Cell的Tag里面

111,126

社区成员

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

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

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