private void TitleRadioButton_CheckedChanged(object sender, EventArgs e) { if (MagazinesDGV.Rows.Count == 0) { return; } WaitForm WF = new WaitForm(); this.Invoke((MethodInvoker) delegate { WF.Show(this); WF.Update(); }); string[] TextToSearch = { "", "" }; if (SygRadioButton.Checked) { TextToSearch[0] = MagazinesDGV.SelectedRows[0].Cells["Sygnatura"].Value.ToString().ToLower(); TextToSearch[1] = MagazinesDGV.SelectedRows[0].Cells["Magazine"].Value.ToString().ToLower(); LoadMagazines("2"); for (int i = 0; i < MagazinesDGV.Rows.Count; i++) { if (MagazinesDGV.Rows[i].Cells["Magazine"].Value.ToString().ToLower().StartsWith(TextToSearch[1].ToLower()) && MagazinesDGV.Rows[i].Cells["Sygnatura"].Value.ToString().ToLower().StartsWith(TextToSearch[0].ToLower())) { MagazinesDGV.ClearSelection(); MagazinesDGV.Rows[i].Selected = true; MagazinesDGV.CurrentCell = MagazinesDGV["Magazine", i]; MagazinesDGV.FirstDisplayedScrollingRowIndex = i; break; } } } else if (TitleRadioButton.Checked) { TextToSearch[0] = MagazinesDGV.SelectedRows[0].Cells["Sygnatura"].Value.ToString().ToLower(); TextToSearch[1] = MagazinesDGV.SelectedRows[0].Cells["Magazine"].Value.ToString().ToLower(); LoadMagazines("1"); for (int i = 0; i < MagazinesDGV.Rows.Count; i++) { if (MagazinesDGV.Rows[i].Cells["Magazine"].Value.ToString().ToLower().StartsWith(TextToSearch[1].ToLower()) && MagazinesDGV.Rows[i].Cells["Sygnatura"].Value.ToString().ToLower().StartsWith(TextToSearch[0].ToLower())) { MagazinesDGV.ClearSelection(); MagazinesDGV.Rows[i].Selected = true; MagazinesDGV.CurrentCell = MagazinesDGV[1, i]; MagazinesDGV.FirstDisplayedScrollingRowIndex = i; break; } } } WF.Close(); MagazinesDGV.Focus(); }
private void MagazinesDGV_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 { SearchText += e.KeyChar.ToString(); label1.Text = SearchText; } //WYSZUKANIE WG WPISANEGO TEKSTU for (int i = 0; i < MagazinesDGV.Rows.Count; i++) { if (/*dataGridView1.Columns.Contains("id") &&*/ ((MagazinesDGV.Columns.Contains("Magazine") && MagazinesDGV.Rows[i].Cells["Magazine"].Value.ToString().ToLower().StartsWith(SearchText.ToLower())) || (MagazinesDGV.Columns.Contains("Sygnatura") && MagazinesDGV.Rows[i].Cells["Sygnatura"].Value.ToString().ToLower().StartsWith(SearchText.ToLower())) || (MagazinesDGV.Columns.Contains("tytul_artykulu") && MagazinesDGV.Rows[i].Cells["tytul_artykulu"].Value.ToString().ToLower().StartsWith(SearchText.ToLower())) || (MagazinesDGV.Columns.Contains("Język") && MagazinesDGV.Rows[i].Cells["Język"].Value.ToString().ToLower().StartsWith(SearchText.ToLower())))) { MagazinesDGV.ClearSelection(); MagazinesDGV.Rows[i].Selected = true; /*if (MagazinesDGV.Columns.Contains("syg")) * MagazinesDGV.CurrentCell = MagazinesDGV["syg", i]; * else if (MagazinesDGV.Columns.Contains("tytul_gl")) * MagazinesDGV.CurrentCell = MagazinesDGV["tytul_gl", i]; * else if (MagazinesDGV.Columns.Contains("tytul_artykulu")) * MagazinesDGV.CurrentCell = MagazinesDGV["tytul_artykulu", i]; * else if (MagazinesDGV.Columns.Contains("Język")) * MagazinesDGV.CurrentCell = MagazinesDGV["Język", i];*/ for (int j = 0; j < MagazinesDGV.Columns.Count; j++) { if (MagazinesDGV.Columns[j].Visible == true) { MagazinesDGV.CurrentCell = MagazinesDGV[j, i]; break; } } MagazinesDGV.FirstDisplayedScrollingRowIndex = i; break; } } }