怎么通过代码 高亮或者选定Datagridview指定行?(选择模式已经设置成FullRowSelect了) 我想通过代码,选定Datagridview需要选定的某一行,该怎么办?找了很久都没找到 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 dataGridView1.Rows[1].Selected = true; dataGridView1.CurrentCell = dataGridView1.Rows[1].Cells[0]; 我知道我需要选定的那一行第一个cell里的内容,比如“008”,那我怎么去选定这一行呢? 如果你的dataGridView1和BingdingSource1绑定,还可以这样操作:BingdingSource1.Position = n; //n为你要选择的项 没有绑定的,都是在代码里的没有用到BingdingSource 如果“那一行第一个cell里的内容”,那恐怕要循环比较了:dataGridView1[0,i].asstring() == "008" 没有绑定,就用“zgke ”的方法 DataGridView.SetCurrentCellAddressCore用这个可以么? zgke是?我也知道是第几行,比如选择第三行,这样就不用去循环比较了 SetCurrentCellAddressCore 是受保护的方法啊,除非你从DataGridView继承一个类,否则根本调用不了 我在datagridview中进行编辑后按回车,就会自动选中下一行,该怎么不让他自动选中下一行呢? dataGridView1.CurrentCell 设置这个不就好了 int i = 0; private void button1_Click(object sender, EventArgs e) { dataGridView1.CurrentCell = dataGridView1.Rows[i].Cells[0]; i++;} private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e){ dataGridView1.CurrentCell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];}这个事件试一下,看行不,我在这次项目中也遇到这样的问题,这样就能选中一行。 恩,你这个方法的确是可以,如果是在button的点击事件里是能做到,但是如果是在dataGridView1_CellValueChanged(单元格的值更改)事件里就不能做到了 private void dgvShopInfo_CellValueChanged(object sender, DataGridViewCellEventArgs e) { //对单元格进行编辑后 string MID = Convert.ToString(dgvShopInfo[0, e.RowIndex].Value).Trim(); if (MID != "") { //如果MID栏里有内容,可以进行update操作 //首先让用户确认 if (MessageBox.Show("确定要对该条库存信息进行修改吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { //进行数据库update操作 dgvShopInfo_CellClick(sender, e);//将当前行内容显示在编辑区内 dgvShopInfo.CurrentCell = dgvShopInfo.Rows[e.RowIndex].Cells[0]; } else { //重新载入数据表 } } } } 这个的确也是对的,但是问题是如果把这条语句添加到dataGridView1_CellValueChanged事件中就不好使了!你试试看。不知道有没有什么解决办法 最好的办法就是重写datagridview控件了!mmdusing System.Windows.Forms;namespace myproj{ public partial class Datagridview_NoNext : System.Windows.Forms.DataGridView { public Datagridview_NoNext() { InitializeComponent(); } //重写控件,DataGridView 单元格编辑后焦点移动到该行的另外一列而不换行 protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { switch (keyData) { case Keys.Enter: { SendKeys.Send("{TAB}"); } return true; } return base.ProcessCmdKey(ref msg, keyData); } }} 请问,如何生成定期事件 C# SOCKET的问题,TCPCLIENT连不出去。 100分 C#安装包升级制作问题请教 导出Excel文件不成功 请大家帮忙看看这个SOCKET程序.. 新手问题……ACCESS操作,可以读取,但是不能修改 格式转换的问题,做过的请进 安装 .NET 时报错!各位高手麻烦想想办法!多谢! 用AxImp.exe转换wmp的ActiveX控件是发生错误,高手来看看啊! 高手:如何在注册页面中读取客户端网卡号并写入数据库? 菜鸟求教!! picturebox上放label卡的问题
dataGridView1.CurrentCell = dataGridView1.Rows[1].Cells[0];
BingdingSource1.Position = n; //n为你要选择的项
dataGridView1[0,i].asstring() == "008"
用这个可以么?
{
dataGridView1.CurrentCell = dataGridView1.Rows[i].Cells[0];
i++;
}
{
dataGridView1.CurrentCell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
}
这个事件试一下,看行不,我在这次项目中也遇到这样的问题,这样就能选中一行。
private void dgvShopInfo_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
//对单元格进行编辑后
string MID = Convert.ToString(dgvShopInfo[0, e.RowIndex].Value).Trim();
if (MID != "")
{
//如果MID栏里有内容,可以进行update操作
//首先让用户确认
if (MessageBox.Show("确定要对该条库存信息进行修改吗?",
"提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
//进行数据库update操作
dgvShopInfo_CellClick(sender, e);//将当前行内容显示在编辑区内
dgvShopInfo.CurrentCell = dgvShopInfo.Rows[e.RowIndex].Cells[0];
}
else
{
//重新载入数据表
} }
}
}
最好的办法就是重写datagridview控件了!mmd
using System.Windows.Forms;namespace myproj
{
public partial class Datagridview_NoNext : System.Windows.Forms.DataGridView
{
public Datagridview_NoNext()
{
InitializeComponent();
}
//重写控件,DataGridView 单元格编辑后焦点移动到该行的另外一列而不换行
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{ switch (keyData)
{
case Keys.Enter:
{
SendKeys.Send("{TAB}");
} return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
}
}