private void gridViewTags_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e) { GridView view = gridViewTags; if (!IsLoaded) { if (!Cleared) { if (view != null && view.SelectedRowsCount > 0) { Cleared = true; view.ClearSelection(); } } if (dictionarySelectedTags != null) { KeyValuePair<string, int> kvTag; questiontag qt; for (int i = 0; i < view.RowCount; i++) { qt = view.GetRow(i) as questiontag; if (qt != null) { kvTag = dictionarySelectedTags.FirstOrDefault(d => d.Value == qt.id); if (kvTag.Key != null && kvTag.Value != 0) { if (!view.IsRowSelected(i)) { view.SelectRow(i); view.FocusedRowHandle = i; } } } } textEditSelectedTags.Text = string.Join(",", dictionarySelectedTags.Keys.ToArray()); } IsLoaded = true; if (view.RowCount <= 0) { btnEditTag.Enabled = false; btnDeleteTag.Enabled = false; } else { btnEditTag.Enabled = true; btnDeleteTag.Enabled = true; } return; } if (view == null || view.SelectedRowsCount == 0) return; if (view.SelectedRowsCount > 1) btnEditTag.Enabled = false; else btnEditTag.Enabled = true; questiontag[] rows = new questiontag[view.SelectedRowsCount]; for (int i = 0; i < view.SelectedRowsCount; i++) { rows[i] = view.GetRow(view.GetSelectedRows()[i]) as questiontag; } view.BeginSort(); dictionarySelectedTags = new Dictionary<string, int>(); try { //[@jeff 09.27.2011]: http://brightvision.jira.com/browse/PLATFORM-541 KeyValuePair<string, int> iTag; foreach (questiontag row in rows) if (row != null) { iTag = new KeyValuePair<string, int>(row.title, row.id); if (!dictionarySelectedTags.Contains(iTag) && !dictionarySelectedTags.Keys.Contains(row.title)) dictionarySelectedTags.Add(row.title, row.id); } } finally { view.EndSort(); } textEditSelectedTags.Text = string.Join(",", dictionarySelectedTags.Keys.ToArray()); }
private void simpleButtonAdd_Click(object sender, EventArgs e) { if (!dxValidationProvider1.Validate()) return; questiontag _efeQuestionTag = null; if (!this.EditMode) { if (this.TagExists(textEditTagname.Text.Trim())) { MessageBox.Show("Tag already exist. Please enter another tag.", "Tags", MessageBoxButtons.OK, MessageBoxIcon.Hand); ParentForm.DialogResult = DialogResult.None; return; } _efeQuestionTag = new questiontag() { title = textEditTagname.Text, description = textEditDescription.Text }; BPContext.questiontags.AddObject(_efeQuestionTag); //BPContext.questiontags.AddObject(new questiontag() { // title = textEditTagname.Text, // description = textEditDescription.Text //}); } else { //var obj = BPContext.questiontags.FirstOrDefault(p => p.id == editID); _efeQuestionTag = BPContext.questiontags.FirstOrDefault(p => p.id == editID); _efeQuestionTag.title = textEditTagname.Text; _efeQuestionTag.description = textEditDescription.Text; } BPContext.SaveChanges(); var datasource = BPContext.questiontags.ToList(); TagsGrid.GridControl.DataSource = datasource; this.textEditTagname.Text = string.Empty; this.textEditDescription.Text = string.Empty; var view = TagsGrid; questiontag oC; if (datasource == null) return; var row = datasource.FirstOrDefault(p => p.id == editID); if (row != null) { for (int i = 0; i < view.DataRowCount; i++) { oC = view.GetRow(i) as questiontag; if (oC != null && row.id == oC.id) { view.FocusedRowHandle = i; break; } } } if (AfterSave != null) AfterSave(this, new AddTagArgs() { QuestionTagId = _efeQuestionTag.id }); ParentForm.Close(); }
private void gridViewTags_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e) { GridView view = gridViewTags; if (!IsLoaded) { if (!Cleared) { if (view != null && view.SelectedRowsCount > 0) { Cleared = true; view.ClearSelection(); } } if (dictionarySelectedTags != null) { KeyValuePair<string, int> kvTag; questiontag qt; for (int i = 0; i < view.RowCount; i++) { qt = view.GetRow(i) as questiontag; if (qt != null) { kvTag = dictionarySelectedTags.FirstOrDefault(d => d.Value == qt.id); if (kvTag.Key != null && kvTag.Value != 0) { if (!view.IsRowSelected(i)) { view.SelectRow(i); view.FocusedRowHandle = i; } } } } textEditSelectedTags.Text = string.Join(",", dictionarySelectedTags.Keys.ToArray()); } IsLoaded = true; return; } if (view == null || view.SelectedRowsCount == 0) return; questiontag[] rows = new questiontag[view.SelectedRowsCount]; for (int i = 0; i < view.SelectedRowsCount; i++) { rows[i] = view.GetRow(view.GetSelectedRows()[i]) as questiontag; } view.BeginSort(); dictionarySelectedTags = new Dictionary<string, int>(); try { foreach (questiontag row in rows) { if (row != null) { dictionarySelectedTags.Add(row.title, row.id); } } } finally { view.EndSort(); } textEditSelectedTags.Text = string.Join(",", dictionarySelectedTags.Keys.ToArray()); }