Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
135
Text not showing in UltraTextEditor
posted

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 Button
dropDownEditorButton.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 control
textEditor.AfterEditorButtonCloseUp += new Infragistics.Win.UltraWinEditors.EditorButtonEventHandler(textEditor_AfterEditorButtonCloseUp);
textEditor.BeforeEditorButtonDropDown += new Infragistics.Win.UltraWinEditors.BeforeEditorButtonDropDownEventHandler(textEditor_BeforeEditorButtonDropDown);

// Populate the multi select grid with data
DataTable 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.RowsIdea;
        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
}