I'm attempting to create a multi select drop down control similar to what is described here: http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=7698
What I have so far is working OK, but one of the biggest problems is that after selections are made, I'd like to update the UltraTextEditor's text property to display the values that were selected. Say, as a comma separated list. But, I cannot get any text to show up for that control. Any suggestions? Here's the code:
UltraGrid multiSelectGrid = new UltraGrid();multiSelectGrid.AfterEnterEditMode += new EventHandler(multiSelectGrid_AfterEnterEditMode);multiSelectGrid.InitializeLayout += new Infragistics.Win.UltraWinGrid.InitializeLayoutEventHandler(multiSelectGrid_InitializeLayout);multiSelectGrid.BeforeEnterEditMode += new System.ComponentModel.CancelEventHandler(multiSelectGrid_BeforeEnterEditMode);DropDownEditorButton dropDownEditorButton = new DropDownEditorButton(); //Dropdown Editor ButtondropDownEditorButton.Control = multiSelectGrid; // The Multi Select "Combo" UltraTextEditor textEditor = new UltraTextEditor();textEditor.DisplayStyle = Infragistics.Win.EmbeddableElementDisplayStyle.Office2003;textEditor.ButtonsRight.Add(dropDownEditorButton); //add the button to the editor controltextEditor.AfterEditorButtonCloseUp += new Infragistics.Win.UltraWinEditors.EditorButtonEventHandler(textEditor_AfterEditorButtonCloseUp);textEditor.BeforeEditorButtonDropDown += new Infragistics.Win.UltraWinEditors.BeforeEditorButtonDropDownEventHandler(textEditor_BeforeEditorButtonDropDown);// Populate the multi select grid with dataDataTable objTable = new DataTable();DataTable customData = objTable;customData.Columns.Add("Checked", typeof(bool));customData.Columns.Add("Text", typeof(string));foreach (ValueListItem item in valueList.ValueListItems){ DataRow objRow = customData.NewRow(); objRow[0] = item.DataValue; objRow[1] = item.DisplayText;
customData.Rows.Add(objRow);}multiSelectGrid.DataSource = objTable;mainGrid.DisplayLayout.Bands[0].Columns[drDropDowns["cfj_ID"].ToString()].ValueList = valueList;mainGrid.DisplayLayout.Bands[0].Columns[drDropDowns["cfj_ID"].ToString()].EditorControl = textEditor;mainGrid.DisplayLayout.Bands[0].Columns[drDropDowns["cfj_ID"].ToString()].InvalidValueBehavior = Infragistics.Win.UltraWinGrid.InvalidValueBehavior.RevertValueAndRetainFocus;
// here's the event handler for the after button close up event on the text editor
void textEditor_AfterEditorButtonCloseUp(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e){ // get custom controls UltraTextEditor textEditor = (UltraTextEditor) sender; DropDownEditorButton dropDownEditorButton = (DropDownEditorButton) textEditor.ButtonsRight[0]; UltraGrid multiSelectGrid = (UltraGrid)dropDownEditorButton.Control; UltraGrid mainGrid = (UltraGrid)textEditor.Parent; // update the values if (multiSelectGrid.ActiveRow == null) return; ValueList valueList = new ValueList(); List<string> values = new List<string>(); for(int i=0; i < multiSelectGrid.Rows.Count; i++) { UltraGridRow row = multiSelectGrid.Rows; bool isChecked = false; try { isChecked = bool.Parse(row.Cells["Checked"].Value.ToString()); } catch{} if (isChecked) { valueList.ValueListItems.Add(row.Cells["Text"].Value.ToString()); values.Add(row.Cells["Text"].Value.ToString()); } } string textToDisplay = String.Join(",", values.ToArray()); textEditor.Text = textToDisplay; // THIS DOESN'T WORK}
mhartman29 said:I'd like to update the UltraTextEditor's text property
I didn't run your code, but I see you are setting the Text property of the button, not the text editor control.
You are correct, I should have been more careful. I'm trying many different things to get it to work, and setting the text on the button was one of those attempts. I've edited the code above for clarity with the original question. Thanks!
Oh... I just realized... you are using this UltraTextEditor in a grid cell? If that's the case, then setting the Text property on the UltraTextEditor will hav no effect on the grid cell. The grid doesn't use the actual text editor control. What you want to do here is set the Value on the grid cell, not the Text on the UltraTextEditor. The e.Context param of the event should give you enough information to get the cell being edited.
Oh, in that case, I'm not sure. I can't see any reason why setting the Text property wouldn't work. Are you sure that line of code is getting hit and that it's actually got a value in the text?