This is a migrated thread and some comments may be shown as answers.

Custom

2 Answers 105 Views
GridView
This is a migrated thread and some comments may be shown as answers.
konrad
Top achievements
Rank 1
konrad asked on 18 Dec 2012, 10:48 AM
Hello,

Edit: Sorry for topic name. Can't update it after posting.

I have RadMultiColumnComboBox in GridView.
I replace editor for that column like that:
private void GridView_EditorRequired(object sender, EditorRequiredEventArgs e)
{
   if (e.EditorType == typeof(RadMultiColumnComboBoxElement))
   {
       PersonChecker newEditor = new PersonChecker();
       e.Editor = newEditor;
   }
}

and this is my custom class:

public class PersonChecker : BaseInputEditor
{
    public override object Value
    {
        get
        {
            String all = "";
 
            RadMultiColumnComboBoxElement editor = ((RadMultiColumnComboBoxElement)this.EditorElement);
 
            foreach (GridViewRowInfo gvri in editor.Rows)
            {
 
                if (Convert.ToBoolean(gvri.Cells[0].Value) == true)
                {
                    if (all != "")
                        all += "; ";
 
                    all += Convert.ToString(gvri.Cells[1].Value);
 
                }
            }
 
            return all;
        }
        set
        {
            Console.WriteLine("to do");
        }
    }
 
    protected override RadElement CreateEditorElement()
    {
        RadMultiColumnComboBoxElement editor = new RadMultiColumnComboBoxElement();
 
        editor.EditorControl.AutoGenerateColumns = false;
        editor.Columns.Clear();
         
        GridViewCheckBoxColumn check = new GridViewCheckBoxColumn();
        check.HeaderText = "";
        check.Name = "Check";
        check.MinWidth = 40;
        check.MaxWidth = check.MinWidth;
        check.ReadOnly = false;
        editor.Columns.Add(check);
     
        GridViewTextBoxColumn username = new GridViewTextBoxColumn();
        username.HeaderText = "Username";
        username.Name = "Username";
        username.MinWidth = 200;
        editor.Columns.Add(username);
 
        editor.Rows.Clear();
 
        editor.Rows.Add(new Object[] { false, "Person 1" });
        editor.Rows.Add(new Object[] { false, "Person 2" });
        editor.Rows.Add(new Object[] { false, "Person 3" });
 
 
        //foreach (Person person in FormMain._persons)
        //{
        //    editor.Rows.Add(
        //    new Object[] { false, person.SP_Username }
        //  );
        //}
 
 
        editor.EditorControl.ShowRowHeaderColumn = false;
        editor.AutoSizeDropDownToBestFit = true;
 
        editor.PopupClosing -= Editor_PopupClosing;
        editor.PopupClosing += Editor_PopupClosing;
 
        editor.EditorControl.CellClick -= EditorControl_CellClick;
        editor.EditorControl.CellClick += EditorControl_CellClick;
 
        return editor;
    }
 
    private void EditorControl_CellClick(object sender, GridViewCellEventArgs e)
    {
        if (e.ColumnIndex == 0 && e.RowIndex > -1)
        {
            e.Row.Cells[0].Value = !Convert.ToBoolean(e.Row.Cells[0].Value);
        }
    }
 
    private void Editor_PopupClosing(object sender, RadPopupClosingEventArgs args)
    {
        if (args.CloseReason == RadPopupCloseReason.Mouse)
        {
            args.Cancel = true;
        }
    }
 
    public override void BeginEdit()
    {
        base.BeginEdit();
        this.EditorElement.Focus();
    }
 
    public override bool EndEdit()
    {
        return base.EndEdit();
    }
 
    public override Type DataType
    {
        get { return typeof(string); }
    }
 
}

So basically when user edit cell, another grid (custom editor) will show and user can check few person. After editing value in that cell will be set like Person 1; Person 2; Person 3.

This all work just fine but i have problem with text in that cell when user is in edit mode.
After entering edit mode cell text automatically change to "False".
When user check some rows cell text also change according to checked state "False" or "True".

How to avoid that text changing?
I want see my current string (depend what was checked) "Person 1; Person 2; Person 3" in grid cell also in edit mode so will be always updated information.
I another words, how to control text displayed in cell when user is in edit mode? 






2 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Petrov
Telerik team
answered on 21 Dec 2012, 08:35 AM
Hi Dominik,

Thank you for writing.

I see that you have come a long way with this solution, but I would like to propose you have a look at the following knowledge base article - Mutiselect drop down list column in RadGridView. The solution there solves the same same problem as you have and achieves the same behavior you want. 

I hope this is useful. If you have further questions, I would be glad to help. 

All the best,
Ivan Petrov
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
0
konrad
Top achievements
Rank 1
answered on 21 Dec 2012, 08:57 AM

I'm going to kill myself :)
That's exacly what i need.
Thank You very much!

Tags
GridView
Asked by
konrad
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
konrad
Top achievements
Rank 1
Share this question
or