首页上一页 1 下一页尾页 1 条记录 1/1页
我明明把CellClick 改成了CellDoubleClick,为什么还是单击一下就弹出窗口了呀?
发表在C#图书答疑
2010-07-06
是否精华
是
否
版块置顶:
是
否
//尊敬的老师,你好,以下代码,我明明把CellClick 改成了CellDoubleClick,为什么还是单击一下就弹出窗口了呀?
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.SqlClient;
namespace dbOpSql
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// private void Form1_Load(object sender, EventArgs e)
// {
// dbOpSql dbOpSql = new dbOpSql();
// SqlConnection conn = new SqlConnection();//实例SqlConnection对象
// conn.ConnectionString = "server=.;database=pubs;uid=sa;pwd=000000";//设置连接字符串
// conn.Open();//打开数据库连接
// //使用 SqlCommand提交查询命令
// SqlCommand cmd = new SqlCommand("select * from jobs", conn);
// //获取数据适配器
// SqlDataAdapter da = new SqlDataAdapter();//
// da.SelectCommand = cmd;
// //填冲DataSet
// DataSet ds = new DataSet();
// da.Fill(ds);
// //绑定DataSet数据
// dataGridView1.DataSource = ds.Tables[0].DefaultView;
// //断开连接
// conn.Close();
// }
// }
//}
private void Form1_Load(object sender, EventArgs e)
{
//实例SqlConnection对象打开数据库连接
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "server=.;database=pubs;uid=sa;pwd=000000";
conn.Open();
//创建SqlDataAdapter对象实例
SqlDataAdapter AdapterSelect = new SqlDataAdapter("select * from jobs", conn);
//创建DataTable对象实例
DataTable dt = new DataTable();
AdapterSelect.Fill(dt);
//填冲控件
dataGridView1.DataSource = dt.DefaultView;
conn.Close();
this.dataGridView1.RowHeadersVisible = true;
}
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
string strtb_01;
//实例SqlConnection对象打开数据库连接
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "server=.;database=pubs;uid=sa;pwd=000000";
conn.Open();
SqlDataAdapter AdapterSelect = new SqlDataAdapter("select * from jobs where job_id='" + dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString() + "'", conn);
//创建DataTable对象实例
//创建DataTable对象实例
DataTable dt = new DataTable();
AdapterSelect.Fill(dt);
strtb_01 = "书籍编号: " + dt.Rows[0][0].ToString() + "\r\n";
strtb_01 += "书籍名称: " + dt.Rows[0][1].ToString() + "\r\n";
strtb_01 += "书籍类别: " + dt.Rows[0][2].ToString() + "\r\n";
strtb_01 += "书籍出版社: " + dt.Rows[0][3].ToString() + "\r\n";
MessageBox.Show(strtb_01, "图书信息");
conn.Close();
}
}
}
}
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.SqlClient;
namespace dbOpSql
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// private void Form1_Load(object sender, EventArgs e)
// {
// dbOpSql dbOpSql = new dbOpSql();
// SqlConnection conn = new SqlConnection();//实例SqlConnection对象
// conn.ConnectionString = "server=.;database=pubs;uid=sa;pwd=000000";//设置连接字符串
// conn.Open();//打开数据库连接
// //使用 SqlCommand提交查询命令
// SqlCommand cmd = new SqlCommand("select * from jobs", conn);
// //获取数据适配器
// SqlDataAdapter da = new SqlDataAdapter();//
// da.SelectCommand = cmd;
// //填冲DataSet
// DataSet ds = new DataSet();
// da.Fill(ds);
// //绑定DataSet数据
// dataGridView1.DataSource = ds.Tables[0].DefaultView;
// //断开连接
// conn.Close();
// }
// }
//}
private void Form1_Load(object sender, EventArgs e)
{
//实例SqlConnection对象打开数据库连接
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "server=.;database=pubs;uid=sa;pwd=000000";
conn.Open();
//创建SqlDataAdapter对象实例
SqlDataAdapter AdapterSelect = new SqlDataAdapter("select * from jobs", conn);
//创建DataTable对象实例
DataTable dt = new DataTable();
AdapterSelect.Fill(dt);
//填冲控件
dataGridView1.DataSource = dt.DefaultView;
conn.Close();
this.dataGridView1.RowHeadersVisible = true;
}
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
string strtb_01;
//实例SqlConnection对象打开数据库连接
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "server=.;database=pubs;uid=sa;pwd=000000";
conn.Open();
SqlDataAdapter AdapterSelect = new SqlDataAdapter("select * from jobs where job_id='" + dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString() + "'", conn);
//创建DataTable对象实例
//创建DataTable对象实例
DataTable dt = new DataTable();
AdapterSelect.Fill(dt);
strtb_01 = "书籍编号: " + dt.Rows[0][0].ToString() + "\r\n";
strtb_01 += "书籍名称: " + dt.Rows[0][1].ToString() + "\r\n";
strtb_01 += "书籍类别: " + dt.Rows[0][2].ToString() + "\r\n";
strtb_01 += "书籍出版社: " + dt.Rows[0][3].ToString() + "\r\n";
MessageBox.Show(strtb_01, "图书信息");
conn.Close();
}
}
}
}