samedi 14 mai 2016

Display specific Column when checkbox is checked

i would like to display a specific column (date of birth, for an example) on a datagridview which is connected to ms access, when a checkbox (date of birth checkbox) is checked, it would help much more if it was an array, because i want to add more than one checkbox. thankyou.

namespace emp_db1
{
public partial class Print : Form
{

    private OleDbConnection connection = new OleDbConnection();
    public Print()
    {
        InitializeComponent();
        connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source = emp_0.mdb";
    }
    DataTable ds;
    private void Print_Load(object sender, EventArgs e)
    {
        try
        {
            connection.Open();
            OleDbCommand command = new OleDbCommand();
            command.Connection = connection;
            command.CommandText = "SELECT ID, Name, DOB FROM emp_per";
            OleDbDataAdapter da = new OleDbDataAdapter(command);
            ds = new DataTable();
            da.Fill(ds);
            dataGridView1.DataSource = ds;
            da.Update(ds);
            connection.Close();
            dataGridView1.AutoResizeColumns();
            dataGridView1.AutoResizeColumnHeadersHeight();
            foreach (DataGridViewColumn col in dataGridView1.Columns)
            {
                col.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            }
            this.dataGridView1.Sort(this.dataGridView1.Columns[0], ListSortDirection.Ascending);
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error " + ex);
        }
    }
    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
    }
    private void dob_check_CheckedChanged(object sender, EventArgs e)
    {   
    }
    }
}




Aucun commentaire:

Enregistrer un commentaire