datagridview单元格单击以填充多个datagridviews

时间:2013-08-28 19:24:51

标签: c# winforms datagridview

单元格单击正在运行但不是预期的。我不得不多次点击,3,以便让其他datagridviews填充数据。有没有办法在单次单击而不是同一行上的倍数完成此操作。

 private void DGV_Daily_Cases_CellContentClick(object sender, DataGridViewCellEventArgs e) //This functionality loads all ROA images
    {
        // Get date-only portion of date, without its time.
        DateTime Cut_Off_Date = cutoff_date.Date;

        DGV_links.Rows.Clear();
        DGV_links.AllowUserToAddRows = false;
        DGV_Fab_5.Visible = true;

        //DGVROA.DataSource = "";

        DGVROA.AllowUserToAddRows = false;
        DGVROA.Refresh();
        txtBarcode.Text = "";
        txtCitation.Text = "";

        //Name of query used for getting Driving Record
        DLqueryString = "SELECT DR_license AS driverlicense ";
        DLqueryString += "FROM brev_driver_history_master ";
        DLqueryString += "WHERE DR_license = ? ";

        DataTable DLtable = new DataTable();
        DLtable.Columns.Add("License", typeof(string));
        DataRow DLrows;


        //fills table with DL information
        OdbcCommand cmd = new OdbcCommand(DLqueryString);
        string conn = "Dsn=something;Persist Security Info=True;User ID=name;Password=password";
        using (OdbcConnection connection = new OdbcConnection(conn))
        {
            cmd.Connection = connection;
            connection.Open();

            cmd.Parameters.Add("@license", OdbcType.VarChar);
            cmd.Parameters["@license"].Value = license;

            OdbcDataReader r = cmd.ExecuteReader();

            while (r.Read())
            {
                license = r["driverlicense"].ToString().TrimEnd();
                DLrows = DLtable.NewRow();
                DLrows["License"] = license;
            }
            r.Close();
            dataGridView2.DataSource = DLtable;

            //Name of query used for getting ROA information
            Eventquery = "SELECT caa38840002 AS event_desc, caa38840001 AS event_code, caa49540064 AS barcode_id, caa50040002 AS image_flag, ";
            Eventquery += "caa50040001, caa495400018 AS caseID, caa49540002 AS event_date, caa49540003 ";
            Eventquery += "FROM caa38840, caa49540, caa50040 ";
            Eventquery += "WHERE caa495400018 = ? ";
            Eventquery += "AND caa49540064 = caa50040001 ";
            Eventquery += "AND caa49540004 = caa38840001 ";
            Eventquery += "AND caa38840001 != 7423 ";
            Eventquery += "ORDER BY caa49540002 DESC, caa49540003";

            DataTable EventTable = new DataTable();
            EventTable.Columns.Add("EventDesc", typeof(string));
            EventTable.Columns.Add("CaseID", typeof(int));
            EventTable.Columns.Add("Barcode", typeof(int));
            EventTable.Columns.Add("EventCode", typeof(int));
            EventTable.Columns.Add("Image", typeof(string));
            EventTable.Columns.Add("EventDate", typeof(DateTime));

            DataRow EventRows;

            //fills table with ROA Event information
            OdbcCommand comm = new OdbcCommand(Eventquery);
            string Eventconnect = "Dsn=something;Persist Security Info=True;User ID=name;Password=password";
            using (OdbcConnection EventConn = new OdbcConnection(Eventconnect))
            {
                comm.Connection = EventConn;
                EventConn.Open();

                comm.Parameters.AddWithValue("caa495400018", Case_ID.Text);


                OdbcDataReader rd = comm.ExecuteReader();

                while (rd.Read())
                {
                    event_desc = rd["event_desc"].ToString().TrimEnd();
                    caseID = Convert.ToInt32(rd["caseID"].ToString().TrimEnd());
                    Event_barcode = Convert.ToInt32(rd["barcode_id"].ToString().TrimEnd());
                    event_code = rd["event_code"].ToString().TrimEnd();
                    image_flag = rd["image_flag"].ToString().TrimEnd();
                    event_date = DateTime.Parse(rd["event_date"].ToString());

                    EventRows = EventTable.NewRow();
                    EventRows["EventDesc"] = event_desc;
                    EventRows["CaseID"] = caseID;
                    EventRows["Barcode"] = Event_barcode;
                    EventRows["EventCode"] = event_code;
                    EventRows["Image"] = image_flag;
                    EventRows["EventDate"] = event_date.ToString("t");
                    EventTable.Rows.Add(EventRows);
                }
                rd.Close();

                DGVROA.DataSource = EventTable;
                DGVROA.AutoResizeColumns();
                DGVROA.AutoResizeRows();
                DGVROA.Columns["EventDesc"].Visible = true;
                DGVROA.Columns["CaseID"].Visible = false;
                DGVROA.Columns["Barcode"].Visible = false;
                DGVROA.Columns["EventCode"].Visible = false;
                DGVROA.Columns["Image"].Visible = false;
                DGVROA.Columns["EventDate"].Visible = false;

                //Name of query used for getting ROA information
                Fabquery = "SELECT caa38840002 AS event_desc, caa38840001 AS event_code, caa49540064 AS barcode_id, caa50040002 AS image_flag, ";
                Fabquery += "caa50040001, caa495400018 AS caseID, caa49540002 AS event_date, caa49540003 ";
                Fabquery += "FROM caa38840, caa49540, caa50040 ";
                Fabquery += "WHERE caa495400018 = ? ";
                Fabquery += "AND caa49540064 = caa50040001 ";
                Fabquery += "AND caa49540004 = caa38840001 ";
                Fabquery += "AND caa38840001 IN (2705, 2706, 2707, 2708, 2709, 2710, 2714, 2715, 2730, 2766, 2767, 2768, 2790, 2818, 5106, 5111, 5112, 5400, 5401, 5402, 5403, 7710, 9058, 9059, 9060, 9061, 9808)";
                Fabquery += "AND caa38840001 != 7423 ";
                Fabquery += "ORDER BY caa49540002 DESC, caa49540003";

                DataTable Fab_5 = new DataTable();
                Fab_5.Columns.Add("EventDesc", typeof(string));
                Fab_5.Columns.Add("CaseID", typeof(int));
                Fab_5.Columns.Add("Barcode", typeof(int));
                Fab_5.Columns.Add("EventCode", typeof(int));
                Fab_5.Columns.Add("Image", typeof(string));
                Fab_5.Columns.Add("EventDate", typeof(DateTime));

                DataRow FabRows;

                //fills table with ROA Event information
                OdbcCommand comman = new OdbcCommand(Fabquery);
                string Fab5connect = "Dsn=something;Persist Security Info=True;User ID=name;Password=password";
                using (OdbcConnection Fab5Conn = new OdbcConnection(Fab5connect))
                {
                    comman.Connection = Fab5Conn;
                    Fab5Conn.Open();

                    comman.Parameters.AddWithValue("caa495400018", Case_ID.Text);


                    OdbcDataReader Fab5rd = comman.ExecuteReader();

                    while (Fab5rd.Read())
                    {
                        event_desc = Fab5rd["event_desc"].ToString().TrimEnd();
                        caseID = Convert.ToInt32(Fab5rd["caseID"].ToString().TrimEnd());
                        Event_barcode = Convert.ToInt32(Fab5rd["barcode_id"].ToString().TrimEnd());
                        event_code = Fab5rd["event_code"].ToString().TrimEnd();
                        image_flag = Fab5rd["image_flag"].ToString().TrimEnd();
                        event_date = DateTime.Parse(Fab5rd["event_date"].ToString());

                        FabRows = Fab_5.NewRow();
                        FabRows["EventDesc"] = event_desc;
                        FabRows["CaseID"] = caseID;
                        FabRows["Barcode"] = Event_barcode;
                        FabRows["EventCode"] = event_code;
                        FabRows["Image"] = image_flag;
                        FabRows["EventDate"] = event_date.ToString("t");
                        Fab_5.Rows.Add(FabRows);
                    }
                    Fab5rd.Close();
                    DGV_Fab_5.DataSource = Fab_5;
                    DGV_Fab_5.AutoResizeColumns();
                    DGV_Fab_5.AutoResizeRows();
                    DGV_Fab_5.Columns["EventDesc"].Visible = true;
                    DGV_Fab_5.Columns["CaseID"].Visible = false;
                    DGV_Fab_5.Columns["Barcode"].Visible = false;
                    DGV_Fab_5.Columns["EventCode"].Visible = false;
                    DGV_Fab_5.Columns["Image"].Visible = false;
                    DGV_Fab_5.Columns["EventDate"].Visible = false;

0 个答案:

没有答案