如何在datagridview上显示多个复选框

时间:2012-11-18 17:47:27

标签: c# sql-server visual-studio-2008 if-statement checkbox

我需要在datagridview上显示多个复选框。

我选择2复选框时有4个复选框,它在datagridview上显示2复选框。

Ex 2复选框。

CheckBox missShw

0001
0002

CheckBox leaveFull

0003
0004

我首先选择CheckBox missShw和CheckBox leaveFull它的输出。

0003
0004

OR 我是第一个选择CheckBox leaveFull和CheckBox missShw它的输出。

0001
0002

我需要输出2个复选框。

0001
0002
0003
0004

现在,我选择2复选框,因此它会向datagridview 显示所有数据,但它不会显示所有数据

此代码:

public void missShw() 
        {
            SqlConnection conn = new SqlConnection(appConn);
            string sql = "SELECT [filesTA].EmpNo,[Employee].Title + ' ' + [Employee].[First Name] + ' ' + [Employee].[Last Name] as 'FullName',[filesTA].ChkDate"
            + ",Convert(nvarchar(5),[filesTA].ChkIn,108) as 'ChkIn',Convert(nvarchar(5),[filesTA].ChkOut,108) as 'ChkOut"
            + ",[filesTA].LateMin"
            + " From [WebSP].[dbo].[filesTA] inner join [WebSP].[dbo].[Employee] on [Employee].EmployeeNo=[filesTA].EmpNo INNER JOIN [WebSP].[dbo].[CompanyData] On [CompanyData].Company = [Employee].Company"
            + " WHERE [filesTA].ChkDate ='" + dateTimePicker.Value.ToString("yyyy-MM-dd") + "'"
            + " and [Employee].Section = '" + cbSection.SelectedValue + "'"
            + " and [Employee].Team = '" + cbTeam.SelectedValue + "'"
            + " and [filesTA].ErrorCode = '2'";

            da = new SqlDataAdapter(sql, Conn);
            DataSet ds = new DataSet();
            da.Fill(ds);
            Conn.Close();

            dgvShow.DataSource = ds.Tables[0];
        }

public void leaveFull()
        {
            SqlConnection conn = new SqlConnection(appConn);
            string sql = "SELECT [filesTA].EmpNo,[Employee].Title + ' ' + [Employee].[First Name] + ' ' + [Employee].[Last Name] as 'FullName',[filesTA].ChkDate"
            + ",Convert(nvarchar(5),[filesTA].ChkIn,108) as 'ChkIn',Convert(nvarchar(5),[filesTA].ChkOut,108) as 'ChkOut"
            + ",[filesTA].LateMin"
            + " From [WebSP].[dbo].[filesTA] inner join [WebSP].[dbo].[Employee] on [Employee].EmployeeNo=[filesTA].EmpNo INNER JOIN [WebSP].[dbo].[CompanyData] On [CompanyData].Company = [Employee].Company"
            + " WHERE [filesTA].ChkDate ='" + dateTimePicker.Value.ToString("yyyy-MM-dd") + "'"
            + " and [Employee].Section = '" + cbSection.SelectedValue + "'"
            + " and [Employee].Team = '" + cbTeam.SelectedValue + "'"
            + " and [filesTA].ErrorCode = '3'";

            da = new SqlDataAdapter(sql, Conn);
            DataSet ds = new DataSet();
            da.Fill(ds);
            Conn.Close();

            dgvShow.DataSource = ds.Tables[0];
        }

//missShw()
        private void checkBox4_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox4.Checked == true)
            {
                missShw();                
            }
        }

//leaveFull()
        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox3.Checked == true)
            {
                leaveFull();                
            }
        }

感谢您的时间。 :)

0 个答案:

没有答案