Example #1
0
        private void FillDataGridView()
        {
            DrawingControl.SetDoubleBuffered(dgvData);
            DrawingControl.SuspendDrawing(dgvData);

            dgvData.DataSource = null;

            dgvData.Columns.Clear();

            dt.Columns.Clear();
            dt.Clear();

            da.Fill(dt);

            dgvData.DataSource = dt.DefaultView;

            dgvData.AutoSizeColumnsMode        = DataGridViewAutoSizeColumnsMode.ColumnHeader;
            dgvData.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
            dgvData.ReadOnly = false;

            //ID
            dgvData.Columns["ID"].Visible  = false;
            dgvData.Columns["ID"].ReadOnly = true;

            //ElementId
            dgvData.Columns["ElementId"].Visible  = false;
            dgvData.Columns["ElementId"].ReadOnly = true;

            //Mark
            dgvData.Columns["Mark"].Visible  = true;
            dgvData.Columns["Mark"].ReadOnly = true;

            dgvData.ClearSelection();

            DrawingControl.ResumeDrawing(dgvData);
        }
Example #2
0
        private void FilterTable(string _tableName)
        {
            tableIsBeingFiltered = true;
            List <string> tableFields = new List <string>();

            con.Open();
            DataColumnCollection col;

            col = dt.Columns;

            foreach (DataColumn column in col)
            {
                if (column.ColumnName != "ID")
                {
                    string param = column.ColumnName;
                    tableFields.Add(param);
                }
            }

            string searchString = txtFilter.Text;

            DrawingControl.SetDoubleBuffered(dgvData);
            DrawingControl.SuspendDrawing(dgvData);

            dgvData.DataSource = null;
            dgvData.Columns.Clear();

            DataView dsView = new DataView();

            dsView = ds.Tables[0].DefaultView;

            BindingSource bs = new BindingSource();

            bs.DataSource = dsView;

            string filterString = FilterLikeString(tableFields, searchString);

            bs.Filter = filterString;

            dgvData.DataSource = bs;

            con.Close();

            dgvData.AutoSizeColumnsMode        = DataGridViewAutoSizeColumnsMode.ColumnHeader;
            dgvData.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
            dgvData.ReadOnly = false;

            //ID
            dgvData.Columns["ID"].Visible  = false;
            dgvData.Columns["ID"].ReadOnly = true;

            //ElementId
            dgvData.Columns["ElementId"].Visible  = false;
            dgvData.Columns["ElementId"].ReadOnly = true;

            //Mark
            dgvData.Columns["Mark"].Visible  = true;
            dgvData.Columns["Mark"].ReadOnly = true;

            dgvData.ClearSelection();

            DrawingControl.ResumeDrawing(dgvData);
        }