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.

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)
        {   
        }
    }
}

thankyou.




Aucun commentaire:

Enregistrer un commentaire