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

Select value from GridViewComboBoxColumn but not from list.

3 Answers 185 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Grish
Top achievements
Rank 1
Grish asked on 30 Jan 2016, 05:58 PM

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..

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 02 Feb 2016, 02:29 PM
Hello ,

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
arezoo
Top achievements
Rank 1
commented on 30 Nov 2022, 11:22 AM

Dear dimitar can you convert these codes to vb.net for me??

I tried but couldn't.

Dinko | Tech Support Engineer
Telerik team
commented on 30 Nov 2022, 01:38 PM

Hi arezoo,

Here is the code from the reply converted to VB. You could consider using our online code converter which converts C# to VB and vice verse.

Public Sub New()
        InitializeComponent()
        Dim col As GridViewTextBoxColumn = New GridViewTextBoxColumn()
        col.Width = 300
        Me.radGridView1.Columns.Add(col)

        For i As Integer = 0 To 10 - 1
            radGridView1.Rows.AddNew()
        Next

       AddHandler radGridView1.EditorRequired, AddressOf radGridView1_EditorRequired
    End Sub

    Private Sub radGridView1_EditorRequired(ByVal sender As Object, ByVal e As EditorRequiredEventArgs)
        If radGridView1.CurrentColumn.Index = 0 Then
            Dim element = New MyRadMultiColumnComboBoxElement()
            element.ClearTextOnValidation = False
            element.BindingContext = Me.BindingContext
            element.ClearTextOnValidation = False
            element.DataSource = New List(Of MyObject) From {
                New MyObject("comment1"),
                New MyObject("comment2")
            }
            element.DisplayMember = "Text"
            element.ValueMember = "Text"
            e.Editor = element
        End If
    End Sub

    Class MyRadMultiColumnComboBoxElement
        Inherits RadMultiColumnComboBoxElement

        Public Overrides Property Value As Object
            Get
                Return Me.Text
            End Get
            Set(ByVal value As Object)
                MyBase.Value = value
            End Set
        End Property

        Protected Overrides ReadOnly Property ThemeEffectiveType As Type
            Get
                Return GetType(RadMultiColumnComboBoxElement)
            End Get
        End Property
    End Class

0
Grish
Top achievements
Rank 1
answered on 02 Feb 2016, 07:53 PM

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..

0
Dimitar
Telerik team
answered on 04 Feb 2016, 09:47 AM
Hello ,

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
Tags
GridView
Asked by
Grish
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Grish
Top achievements
Rank 1
Share this question
or