Select value from GridViewComboBoxColumn but not from list.

4 posts, 0 answers
  1. Grish
    Grish avatar
    2 posts
    Member since:
    Jan 2016

    Posted 30 Jan Link to this post

    I have RadGridView and in that I have GridViewComboBoxColumn column (name is Comment). End user must select from the value for that column from GridViewComboBoxColumn  list, or write the new value in that field. The problem is that when I write new value that isn't from list, after leaving that column new value not saved. Which option must i set in  GridViewComboBoxColumn or other place.

    Thank you..

  2. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 02 Feb Link to this post

    Hello Grish,

    Thank you for writing.

    By default when a GridViewMultiComboBoxColumn is used, the value is synchronized with the items in the drop down. To achieve the desired behavior, you can use a text box column and change the editor. In addition, you should create a custom editor and return the entered text:
    public RadForm1()
    {
        InitializeComponent();
     
        GridViewTextBoxColumn col = new GridViewTextBoxColumn();
     
        col.Width = 300;
        
        this.radGridView1.Columns.Add(col);
     
        for (int i = 0; i < 10; i++)
        {
            radGridView1.Rows.AddNew();
        }
         
        radGridView1.EditorRequired += radGridView1_EditorRequired;
    }
     
    void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
    {
        if (radGridView1.CurrentColumn.Index == 0)
        {
            var element = new MyRadMultiColumnComboBoxElement();
            element.ClearTextOnValidation = false;
            element.BindingContext = this.BindingContext;
            element.ClearTextOnValidation = false;
            element.DataSource = new List<MyObject>
            {
                new MyObject("comment1"),
                new MyObject("comment2")
            };
            element.DisplayMember = "Text";
            element.ValueMember = "Text";
          
            e.Editor = element;
        }
    }
     
    class MyRadMultiColumnComboBoxElement : RadMultiColumnComboBoxElement
    {
      
        public override object Value
        {
            get
            {
               return this.Text;
            }
            set
            {
                base.Value = value;
            }
        }
     
        protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(RadMultiColumnComboBoxElement);
            }
        }
    }

    Let me know if I can assist you further.
     
    Regards,
    Dimitar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Grish
    Grish avatar
    2 posts
    Member since:
    Jan 2016

    Posted 02 Feb in reply to Dimitar Link to this post

    Thank you Dimitar for your answer. I have resolved that problem with your answer. But i have other one.  

    void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
            {
                RadMultiColumnComboBoxElement multiComboElement = this.radGridView1.ActiveEditor as RadMultiColumnComboBoxElement;
      
                if (multiComboElement != null)
                {
                    multiComboElement.EditorControl.MasterGridViewTemplate.BestFitColumns();
                    multiComboElement.AutoSizeDropDownToBestFit = true;
                    multiComboElement.DropDownSizingMode = SizingMode.UpDownAndRightBottom;
      
      
                    multiComboElement.AutoCompleteMode = AutoCompleteMode.None;
                    multiComboElement.DropDownStyle = RadDropDownStyle.DropDown;
                    multiComboElement.AutoFilter = true;
      
      
                    if (multiComboElement.EditorControl.MasterGridViewTemplate.FilterExpressions.Count == 0)
                    {
      
                        FilterExpression autoFilter = new FilterExpression(multiComboElement.DisplayMember, FilterExpression.BinaryOperation.AND,
                            _inputmethod, GridFilterCellElement.ParameterName);
      
      
      
      
                        autoFilter.Parameters.Add(GridFilterCellElement.ParameterName, "");
      
                        multiComboElement.EditorControl.MasterGridViewTemplate.FilterExpressions.Add(autoFilter);
    }
    }
    }
    In this code I set AutoFilter = true; That is when drop down list filtered, and in list is only one filtred element, column value is equal to that element automatically (Auto Complete is working). This always distrib type new values, that isn't in list for the end user.As you can see I set multiComboElement.AutoCompleteMode = AutoCompleteMode.None; But this not halp me. Thank you..

  5. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 04 Feb Link to this post

    Hello Grish,

    Thank you for writing back.

    Could you please specify which version you are using? I am asking you this because I am unable to compile your code with the latest version.

    In addition, I have tested this by enabling the AutoFilter functionality like described in the following article: Filtering. On my side, pressing Tab will keep the custom text, pressing Enter will select the item from the drop down. What is the exact behavior on your side?

    I am looking forward to your reply.

    Regards,
    Dimitar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top