在gridview中获取列号或列标题 [英] getting the column number or column header in gridview

查看:293
本文介绍了在gridview中获取列号或列标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

双击后如何在datagridview中获取选定的列号或列标题?
我想在该列中放置日期时间选择器.
我使用的代码是这样的:

How to get the selected column number or column header in datagridview, when doubleclick is made?
and i want to place date time picker in that column.
the code which I have used is this one:

void DataGridView1DoubleClick(object sender, EventArgs e)
{
MouseEventArgs args = (MouseEventArgs)e;
Point p = dataGridView1.PointToClient(new Point(args.X,args.Y));
DataGridView.HitTestInfo info = dataGridView1.HitTest(p.X, p.Y);
int Row = info.RowIndex;
int Col=info.ColumnIndex;
 
if(dataGridView1.Columns[info.ColumnIndex].Name == "Employee name")
     {

textBox1.Text="hello";            	textBox1.SetBounds(args.X,args.Y,dataGridView1.CurrentCell.Size.Width,dataGridView1.CurrentCell.Size.Height);
            	textBox1.Show();
            }
}


但行索引和列索引返回为-1
我之所以在column [0]使用复选框列是因为那个?
预先感谢


but the row index and column index is returned as -1
I have used checkbox column at column[0] is this because of that??
thanks in advance

推荐答案

这是我找到的解决方案,它为我提供了选定的列值.但是现在我的问题是如何在该单元格内放置文本框. br/>
int Col = dataGridView1.CurrentCellAddress.X;
this is the solution i found which gives me the column value selected.but now my question is how to place text box inside that cell..

int Col=dataGridView1.CurrentCellAddress.X;


这篇关于在gridview中获取列号或列标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆