private void LoadGrids(SqlCommand Command, DataGridViewColumn[] ColumnsName) { try { AvailableDataGridView.AutoGenerateColumns = false; SelectedDataGridView.AutoGenerateColumns = false; DataGridViewColumn Column; for (int i = 0; i < ColumnsName.Length; i++) { Column = new DataGridViewColumn(new DataGridViewTextBoxCell()); Column.Name = ColumnsName[i].Name; Column.DataPropertyName = ColumnsName[i].DataPropertyName; Column.HeaderText = ColumnsName[i].HeaderText; AvailableDataGridView.Columns.Add(Column); SelectedDataGridView.Columns.Add(ColumnsName[i]); } SelectedDataGridView.Columns["id"].Visible = false; AvailableDataGridView.DataSource = CommonFunctions.ReadData(Command, ref Settings.Connection); AvailableDataGridView.Columns["id"].Visible = false; AvailableDataGridView.Focus(); } catch (Exception Ex) { MessageBox.Show(Ex.Message); } }
private void AvailabeDataGridView_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == '\b') { if (SearchText.Length > 0) { SearchText = SearchText.Remove(SearchText.Length - 1); label1.Text = SearchText; } e.Handled = true; } else if (e.KeyChar == (char)13) { return; } else { SearchText += e.KeyChar.ToString(); label1.Text = SearchText; } for (int i = 0; i < AvailableDataGridView.Rows.Count; i++) { if (AvailableDataGridView.Rows[i].Cells[1].Value.ToString().ToLower().StartsWith(SearchText.ToLower())) { AvailableDataGridView.ClearSelection(); AvailableDataGridView.Rows[i].Selected = true; AvailableDataGridView.CurrentCell = AvailableDataGridView[1, i]; AvailableDataGridView.FirstDisplayedScrollingRowIndex = i; break; } } }