Size of DropDown

36 posts, 2 answers
  1. Ralitsa
    Admin
    Ralitsa avatar
    176 posts

    Posted 05 Aug 2014 Link to this post

    Hi Suresh, 

    Thank you for writing back. 

    Yes, you can use the same approach which my colleague provided in this forum thread on 6th May 2011. I also attached you the modified sample project. 

    Should you have further questions, I would be glad to help. 

    Regards,
    Ralitsa
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  2. Suresh
    Suresh avatar
    4 posts
    Member since:
    Aug 2014

    Posted 05 Aug 2014 in reply to Ralitsa Link to this post

    Thank you so much, it works well...
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Rodolphe Iainh
    Rodolphe Iainh avatar
    3 posts
    Member since:
    Jun 2016

    Posted 29 Jun Link to this post

    Hello, 

    I'm DenisCL. Since I've lost my ids, i'll post from now with this account.

    I have a simple question, regarding the code you previously gave me for the dropdownlist max sized popup.

    I need the same but for ComboboxColumn in radgridview !

    I found how to do it, but I find difficulties to get the current dropdownlist in the radgridview.  I saw we can use the activeEditor for getting the elementEditor and then go ahead.

    But the active editor is null, and I 'm stuck.

    Any ideas?

     

    Here is my code 

                RadDropDownListEditor editor = radGridView1.EditorManager.ActiveEditor as RadDropDownListEditor;
                if (editor != null)
                {
                    _element = editor.EditorElement as RadDropDownListEditorElement;
                    if (_element != null)
                    {
                        _element.PopupOpened += element_PopupOpened;
                    }
                }

    Can you tell me how to access to the dropdownlist  in a cell properly please?

    thanks

     

  5. Rodolphe Iainh
    Rodolphe Iainh avatar
    3 posts
    Member since:
    Jun 2016

    Posted 29 Jun Link to this post

    Hello, 
    I'm DenisCL. Since I've lost my ids, i'll post from now with this account.
    I have a simple question, regarding the code you previously gave me for the dropdownlist max sized popup.
    I need the same but for ComboboxColumn in radgridview !
    I found how to do it, but I find difficulties to get the current dropdownlist in the radgridview.  I saw we can use the activeEditor for getting the elementEditor and then go ahead.
    But the active editor is null, and I 'm stuck.
    Any ideas?

    Here is my code 

                RadDropDownListEditor editor = radGridView1.EditorManager.ActiveEditor as RadDropDownListEditor;
                if (editor != null)
                {
                    _element = editor.EditorElement as RadDropDownListEditorElement;
                    if (_element != null)
                    {
                        _element.PopupOpened += element_PopupOpened;
                    }
                }

    Can you tell me how to access the dropdownlist  in a cell properly please?
    Thanks

  6. Rodolphe Iainh
    Rodolphe Iainh avatar
    3 posts
    Member since:
    Jun 2016

    Posted 29 Jun in reply to Rodolphe Iainh Link to this post

    Sorry for double post...

    I could finally obtain what I need.

    here is the code

    This first function register events on popup and keypress asap the editor is initialized

      void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
            {
                if (_element == null)
                {
                    var editor = radGridView1.EditorManager.ActiveEditor as RadDropDownListEditor;
                    if (editor != null)
                    {
                        _element = editor.EditorElement as RadDropDownListEditorElement;
                        if (_element != null)
                        {
                            _element.PopupOpened += element_PopupOpened;
                            _element.KeyPress += _element_KeyPress;
                        }

                    }
                }
            }

    Then when we open the dropdownlist, it checks the width of every item and take the biggest width. I add 50 for including scrollbar width

     void element_PopupOpened(object sender, EventArgs e)
            {
                SetDropDownSize();
            }

            private void SetDropDownSize()
            {
                int choixPlusLarge = _element.Items.Select(item => TextRenderer.MeasureText(item.Text, item.Font).Width).Concat(new[] {0}).Max() + 40;
                _element.Popup.MinimumSize = new Size(choixPlusLarge, _element.Popup.Height);
            }

  7. Ralitsa
    Admin
    Ralitsa avatar
    176 posts

    Posted 30 Jun Link to this post

    Hi Rodolphe,

    Thank you for contacting us. 

    The CellEditorInitialized event is fired when an editor element of a cell is initialized and visible. One of the event arguments gives information for the active editor. If RadGridView contains more than one GridViewComboBoxColumn, you can check for which column the event is fired. Please refer to the code snippet below how to achieve it: 
    RadDropDownListEditor editor;
    RadDropDownListEditorElement listEditorElement;
     
    void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
        if (e.ColumnIndex == 0 && e.RowIndex == 2)
        {
            if (e.ActiveEditor is RadDropDownListEditor)
            {
                editor = e.ActiveEditor as RadDropDownListEditor;
                listEditorElement = (RadDropDownListEditorElement)editor.EditorElement;
                //listEditorElement.DropDownWidth = 150;
                //listEditorElement.DropDownHeight = 100;
                listEditorElement.PopupOpened += listEditorElement_PopupOpened;
            }
        }
    }

    If this is not what you want to achieve, I would kindly ask you to send me a more detailed explanation about your case. Any additional materials like code snippet or sketches would also be helpful.

    Let me know if I can assist you further.

    Regards,
    Ralitsa
    Telerik
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Back to Top
UI for WinForms is Visual Studio 2017 Ready