Typing inside a RadGridView cell

7 posts, 1 answers
  1. Hila
    Hila avatar
    5 posts
    Member since:
    Sep 2012

    Posted 02 Apr 2012 Link to this post

    Hello,

    I'm using your 

     

    Telerik.WinControls.UI dll version 2011.3.11.1219

     
    and working with RadGridView  object.
    I have a RadGridView which contains a large possible values. (0-200000)
    Right now the user can type the requested value inside a cell and than press ENTER.
    The problem is that if I stand on a cell I can type a number but there is no visual feedback to the user that the cell is in edit mode.
    I would like to mark (select) the current text on the cell when it's in EDIT mode (when user is typing and havn't pressed ENTER to end the editing, which means- found the number he wanted).
    I tried to look for a property which will mark the text in the cell but found nothing...

    dataGridViewSelectedValues.Rows[e.RowIndex]. -> No appropriate property!!








        


    Another question would be- where do I marking the text- inside

    CellClick event or inside CellBeginEdit event ?

     














    I'm attaching an image file that will demonstrate how my RadGridView is looking.
    The lower image is how it looks when the user is typing 12 and the focus is still in the cell- there is no clue that we are in an EDIT mode.









    Thanks,
    Hila.

     

  2. Answer
    Jack
    Admin
    Jack avatar
    2333 posts

    Posted 02 Apr 2012 Link to this post

    Hi Hila,

    Thank you for contacting us.

    The down arrow which appears on right part of the cell when typing indicates that the cell is in edit mode. However, I noted that you are using a drop down list editor in your application. By default RadGridView shows this editor in drop down list mode. In this mode there is no editable part and you cannot select the text. Instead, you can handle the CellEditorInitialized event and changed the whole editor background:
    void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
        RadDropDownListEditor editor = this.radGridView1.ActiveEditor as RadDropDownListEditor;
        if (editor != null)
        {
            RadDropDownListEditorElement editorElement = (RadDropDownListEditorElement)editor.EditorElement;
            editorElement.EditableElement.BackColor = Color.Red;
            editorElement.EditableElement.DrawFill = true;
        }
    }

    Another option is to change the DropDownStyle property of the column to DropDown and to change the auto complete mode to Append:
    GridViewComboBoxColumn c = new GridViewComboBoxColumn("cc");
    c.DataSource = t;
    c.DisplayMember = "Name";
    c.ValueMember = "ID";
    c.DropDownStyle = RadDropDownStyle.DropDown;
    c.AutoCompleteMode = AutoCompleteMode.Append;
    this.radGridView1.Columns.Add(c);

    I hope this helps. If you need further assistance, do not hesitate to write back.
     
    Kind regards,
    Jack
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  3. Hila
    Hila avatar
    5 posts
    Member since:
    Sep 2012

    Posted 02 Apr 2012 Link to this post

    Thanks Jack,

    That was helpful!

    Hila.
  4. Hila
    Hila avatar
    5 posts
    Member since:
    Sep 2012

    Posted 05 Apr 2012 Link to this post

    Hi Jack,

    I have another question related to the same issue.

    I used the second solution you suggested and change it to be:

    colType.DropDownStyle = RadDropDownStyle.DropDown;
    colType.AutoCompleteMode = AutoCompleteMode.SuggestAppend; -> instead of APPEND.


    The only problem is the that for firing the "CellEndEdit" event I need to:

    * After selecting a value from the list with KEBORD (tyyping a value or go through the list values with the seybord up/down arrows)-
        for selecting it I press ENTER but than I must press ENTER again in order to fire the CellEndEdit event (which select the value and removes it from another list)

    * To select value from the list I have to DOUBLE click the value.

    What should I change in order that one ENTER and one CLICK on the desired value would fire the CellEndEdit event?

    Thanks,
    Hila.
  5. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 09 Apr 2012 Link to this post

    Hi Hila,

    You can do this by replacing the default drop down list editor with a custom one. Please, consider the code snippet below:
    public class CustomDropDownListEditor : RadDropDownListEditor
    {
        protected override RadElement CreateEditorElement()
        {
            return new CustomDropDownListEditorElement();
        }
    }
     
    public class CustomDropDownListEditorElement : RadDropDownListEditorElement
    {
        protected override RadPopupControlBase CreatePopupForm()
        {
            this.Popup = new CustomDropDownPopupForm(this);
            this.Popup.VerticalAlignmentCorrectionMode = AlignmentCorrectionMode.SnapToOuterEdges;
            this.Popup.SizingMode = this.DropDownSizingMode;
            this.Popup.Height = this.DropDownHeight;
            this.Popup.HorizontalAlignmentCorrectionMode = AlignmentCorrectionMode.Smooth;
            this.Popup.RightToLeft = this.RightToLeft ? System.Windows.Forms.RightToLeft.Yes : System.Windows.Forms.RightToLeft.Inherit;
     
            this.WirePopupFormEvents(this.Popup);
            return Popup;
        }
    }
     
    public class CustomDropDownPopupForm : DropDownPopupForm
    {
        public CustomDropDownPopupForm(RadDropDownListElement owner): base(owner) {}
             
        public override string ThemeClassName
        {
            get { return typeof(DropDownPopupForm).FullName; }
            set {}
        }
     
        public override void ClosePopup(PopupCloseInfo info)
        {           
            base.ClosePopup(info);
            if (info.CloseReason == RadPopupCloseReason.Keyboard)
            {
                ((RadGridView)this.OwnerElement.ElementTree.Control).EndEdit();
            }
        }
     
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);           
            ((RadGridView)this.OwnerElement.ElementTree.Control).EndEdit();
        }
    }

    You should handle the EditorRequired event to replace the editor:
    void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
    {
        if (e.EditorType == typeof(RadDropDownListEditor))
        {
            e.EditorType = typeof(CustomDropDownListEditor);
        }
    }

    I hope this helps.
     
    Greetings,
    Jack
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  6. Hila
    Hila avatar
    5 posts
    Member since:
    Sep 2012

    Posted 09 Apr 2012 Link to this post

    Hi Jack,

    Thanks for answering.

    I have another quwstion (if you don't mind):
    Is there a way to cancel edit of a cell when you inside EndCellEdit event?
    I have a cell which have a list of allowed values. (ArrayList in DataSource property).

    When I type inside a cell a value that is not in the ALLOWED list->  e.Value ==null  inside EndCellEdit event.
    when I do the same check (inside EndCellEdit event):
    var cellValue = e.Value;
          
          if (cellValue == null)
          {
            return;
          }


    Than the value in the cell is null (empty cell).

    How can I cancel the edit or just set back the old value?

    Thanks,
    Hila.
  7. Svett
    Admin
    Svett avatar
    728 posts

    Posted 11 Apr 2012 Link to this post

    Hello Hila,

    You cannot do the desired action in the CellEndEdit event. Instead, you can do it instead in the CellValidating event. The event occurs when you change the current cell or perform end of the editing operation.

    You can use the following code snippet:

    private void radGridView1_CellValidating(object sender, CellValidatingEventArgs e)
    {
        if (e.ActiveEditor != null)
        {
            // Your action here
            e.Cancel = true;
        }
    }

    I hope this helps.

    Greetings,
    Svett
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top