DataGridView无法触发cellclick事件,selectmode属性已经设置成FullRowSelect,还需要设置什么?
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Da...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Ceshi
{
public partial class Form1 : Form
{
string id = "";
public Form1()
{
InitializeComponent();
}
void GetHuoWu()
{
try
{
string sql = "select ID, Name from Huiyuan";
dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = DB.GetDataTable(sql);
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
private void Form1_Load(object sender, EventArgs e)
{
GetHuoWu();
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
DataGridViewRow dgvr = dataGridView1.CurrentRow;
id = dgvr.Cells[0].Value.ToString();
OleDbConnection con = DB.GetCon();
try
{
con.Open();
string sql = "select * from Huiyuan where ID=" + id + "";
OleDbCommand cmd = new OleDbCommand(sql, con);
OleDbDataReader sr = cmd.ExecuteReader();
if (sr.Read())
{
textBox1.Text = sr["Name"].ToString();
}
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
finally
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
}
}
}
}
点了也没反应 高手请指教~~~~~~~~万分感谢
没人知道么 高手指点下啊 展开
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Ceshi
{
public partial class Form1 : Form
{
string id = "";
public Form1()
{
InitializeComponent();
}
void GetHuoWu()
{
try
{
string sql = "select ID, Name from Huiyuan";
dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = DB.GetDataTable(sql);
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
private void Form1_Load(object sender, EventArgs e)
{
GetHuoWu();
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
DataGridViewRow dgvr = dataGridView1.CurrentRow;
id = dgvr.Cells[0].Value.ToString();
OleDbConnection con = DB.GetCon();
try
{
con.Open();
string sql = "select * from Huiyuan where ID=" + id + "";
OleDbCommand cmd = new OleDbCommand(sql, con);
OleDbDataReader sr = cmd.ExecuteReader();
if (sr.Read())
{
textBox1.Text = sr["Name"].ToString();
}
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
finally
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
}
}
}
}
点了也没反应 高手请指教~~~~~~~~万分感谢
没人知道么 高手指点下啊 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询