已有56人关注
我明明把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();
            }

        }
    }
}
分享到:
精彩评论 1
小科_mrkj
学分:43 LV2
2010-07-06
沙发
读者朋友:
    您好,你是不是只在代码中修改了,在窗体设计界面中选中控件,然后在其事件对话框中,需要触发该控件的CellDoubleClick事件。
首页上一页 1 下一页尾页 1 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照