private void FillGrid(bool refreshList = true, bool isScrollToSelection = true) { if (refreshList) { _listQueries = UserQueries.GetDeepCopy(); } string[] strSearchTerms = Regex.Split(textSearch.Text, @"\W"); //matches any non-word character //get all queries that contain ALL of the search terms entered, either in the query text or the query description. List <UserQuery> listDisplayQueries = _listQueries .Where(x => strSearchTerms.All(y => x.QueryText.ToLowerInvariant().Contains(y.ToLowerInvariant()) || x.Description.ToLowerInvariant().Contains(y.ToLowerInvariant()) )).ToList(); //attempt to preserve the currently selected query. long selectedQueryNum = 0; if (gridMain.GetSelectedIndex() != -1) { selectedQueryNum = gridMain.SelectedTag <UserQuery>().QueryNum; } gridMain.BeginUpdate(); gridMain.ListGridColumns.Clear(); gridMain.ListGridColumns.Add(new GridColumn(Lan.g(gridMain.TranslationName, "Query"), 350)); if (Security.IsAuthorized(Permissions.UserQueryAdmin, true)) { gridMain.ListGridColumns.Add(new GridColumn(Lan.g(gridMain.TranslationName, "Released"), 55, HorizontalAlignment.Center)); } gridMain.ListGridRows.Clear(); foreach (UserQuery queryCur in listDisplayQueries) { if (!Security.IsAuthorized(Permissions.UserQueryAdmin, true) && !queryCur.IsReleased) { continue; //non-released queries only appear for people with UserQueryAdmin permission. } GridRow row = new GridRow(); row.Cells.Add(queryCur.Description); if (Security.IsAuthorized(Permissions.UserQueryAdmin, true)) { row.Cells.Add(queryCur.IsReleased ? "X" : ""); } row.Tag = queryCur; gridMain.ListGridRows.Add(row); } gridMain.EndUpdate(); int selectedIdx = gridMain.ListGridRows.Select(x => (UserQuery)x.Tag).ToList().FindIndex(y => y.QueryNum == selectedQueryNum); if (selectedIdx > -1) { gridMain.SetSelected(selectedIdx, true); } if (gridMain.GetSelectedIndex() == -1) { gridMain.SetSelected(0, true); //can handle values outside of the row count (so if there are no rows, this will not fail) } if (isScrollToSelection) { gridMain.ScrollToIndex(gridMain.GetSelectedIndex()); //can handle values outside of the row count } RefreshQueryCur(); }
private void gridMain_CellClick(object sender, ODGridClickEventArgs e) { if (gridMain.SelectedGridRows.Count == 0) //When deselecting with CTR+Click. { return; } GotoModule.GotoChart(PIn.Long(gridMain.SelectedTag <DataRow>()["PatNum"].ToString())); }
private void butOK_Click(object sender, EventArgs e) { if (IsSelectionMode && gridMain.SelectedIndices.Length > 0) { SelectedClinicNum = gridMain.SelectedTag <Clinic>()?.ClinicNum ?? 0; ListSelectedClinicNums = gridMain.SelectedTags <Clinic>().Select(x => x.ClinicNum).ToList(); DialogResult = DialogResult.OK; } Close(); }
private void butDelete_Click(object sender, System.EventArgs e) { if (gridZipCode.SelectedIndices.Length == 0) { MessageBox.Show(Lan.g(this, "Please select an item first.")); return; } ZipCode ZipCur = gridZipCode.SelectedTag <ZipCode>(); if (MessageBox.Show(Lan.g(this, "Delete Zipcode?"), "", MessageBoxButtons.OKCancel) != DialogResult.OK) { return; } changed = true; ZipCodes.Delete(ZipCur); FillGrid(); }