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

MultiColumnComboBox selected value not working in the case of USERCONTROLER

1 Answer 782 Views
MultiColumn ComboBox
This is a migrated thread and some comments may be shown as answers.
Jihad
Top achievements
Rank 1
Jihad asked on 29 Sep 2020, 02:20 PM

Hello , 

I need to change the selected value in my parent form but the component is in the user controller .

So when I set the value to the multicombobox does not work knowing that the text and selected index take the value well .

 

                    Dim page As New RadPageViewPage()
                    Dim panel As New MyPanel()
                    strip= TryCast(RadPage1.ViewElement, RadPageViewStripElement)
                    page.Text = "page" & (strip.Items.Count + 1)
                   
                    Dim Liste1 As List(Of object) 
                    panel.RadMultiColCmbo1.DisplayMember = "Name"
                    panel.RadMultiColCmbo1.ValueMember = "PK"
                    panel.RadMultiColCmbo1.DataSource = Liste1

                    dim object 1 = myobject 

                   panel.RadMultiColCmbo1.Selectedvalue =myobject.PK 

 

Please help! 

Thank you 

                    
                 

       

1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 02 Oct 2020, 01:14 PM

Hello, Jihad,

If I understand you correctly, you have RadMultiColumnComboBox control which you use within a UserControl and you want to set the SelectedValue property to some value in the parent form.

I created a sample project where I created a user control with RadMultiColumnComboBox in order to test this and it seems to work correctly on my end. When I set the SelectedValue property in the main form the value is shown correctly in the multicolumn combo box.

Public Class UserControl1
    Public Sub New()
        InitializeComponent()
        Dim people As List(Of Person) = New List(Of Person)()

        For i As Integer = 0 To 50 - 1
            people.Add(New Person() With {
                .Id = i,
                .Name = "Name " & i
            })
        Next

        Me.RadMultiColumnComboBox1.DataSource = people
        Me.RadMultiColumnComboBox1.ValueMember = "Id"
        Me.RadMultiColumnComboBox1.DisplayMember = "Name"
    End Sub

    Public ReadOnly Property RadMultiColumnComboBox As RadMultiColumnComboBox
        Get
            Return Me.RadMultiColumnComboBox1
        End Get
    End Property
End Class

Public Class Person
    Public Property Id As Integer
    Public Property Name As String
End Class

' Main Form
Public Class RadForm1
    Public Sub New()
        InitializeComponent()
        Dim control As UserControl1 = New UserControl1()
        Me.Controls.Add(control)
        control.RadMultiColumnComboBox.SelectedValue = 2
    End Sub
 End Class

I attached my test project for your reference. Could you please refer to it and let me know how it differs from your set up?

I am looking forward to your reply.

Regards,
Nadya
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Justine
Top achievements
Rank 1
commented on 21 Mar 2023, 12:43 PM

Hi Support Team,

I have a C# winforms application using RadMultiColumComboBox (with data populating from another table in SQL Server) and while saving the selected record, the selectedvalue is not getting assigned and when we retrieve the saved record from database, the selectedvalue eveen after assigning multiple times will be null always and the selectedindex also will be -1 always. Please help me to overcome these issues.

this.rmcBrand.SelectedValue = Convert.ToInt32(fkBrand); This code is used to assign also, not working and the selected value is always null.

Below is the method used to assign the saved value from database to the control while loading the saved records.

public static string SetValueMultiColumnCombo(Telerik.WinControls.UI.RadMultiColumnComboBox control, string columnName, string columnValue)

{

DataRow[] drselectedItem = dtTemp.Select($"{columnName } = {columnValue}");
                        if (drselectedItem != null && drselectedItem.Length > 0)
                        {
                            int selectedIndex = dtTemp.Rows.IndexOf(drselectedItem[0]);
                            control.SelectedIndex = selectedIndex; //Getting error from here as selectedindex value is -1 always.
                        }

}

 

 

 

Dess | Tech Support Engineer, Principal
Telerik team
commented on 21 Mar 2023, 12:52 PM

Hi, Justine, According to the provided information, it wouldn't be easy to determine what causes this undesired behavior on your end. Could you please elaborate? What is the exact setup in RadMultiColumnComboBox? Please have in mind that the SelectedValue corresponds to the specified ValueMember referring to the respective field in the applied DataSource collection. Could you please specify the exact steps how to reproduce the problem or get back to me with a complete sample code snippet so I can investigate the precise case? 
Justine
Top achievements
Rank 1
commented on 21 Mar 2023, 01:00 PM

private void BindBrandMultiColomnComboBox(RadMultiColumnComboBox radMultiColumnComboBox)
        {            
            DataView dvBrand = new DataView(this.dsProduct.Tables["tblBrand"]);            
            string currentText = radMultiColumnComboBox.Text;
            radMultiColumnComboBox.ClearTextOnValidation = false;            

            //DataRow emptyRow = dvBrand.Table.NewRow();
            //emptyRow["PKBrand"] = 0;
            //emptyRow["BrandName"] = "";
            //emptyRow["TaxCertificates"] = false;
            //dvBrand.Table.Rows.InsertAt(emptyRow, 0);            

            radMultiColumnComboBox.DisplayMember = "BrandName";
            radMultiColumnComboBox.ValueMember = "PKBrand";
            radMultiColumnComboBox.DataSource = dvBrand;

            //set filter
            radMultiColumnComboBox.AutoFilter = true;

            CompositeFilterDescriptor compositeFilter = new CompositeFilterDescriptor();
            FilterDescriptor ftBrand = new FilterDescriptor("BrandName", FilterOperator.Contains, "");            
            compositeFilter.FilterDescriptors.Add(ftBrand);            
            //compositeFilter.LogicalOperator = FilterLogicalOperator.Or;
            radMultiColumnComboBox.EditorControl.FilterDescriptors.Add(compositeFilter);

            ((BaseComboBoxElement)radMultiColumnComboBox.MultiColumnComboBoxElement.EditorElement).TextBoxElement.TextBoxItem.TextBoxControl.CharacterCasing = CharacterCasing.Upper;          


            if (currentText.Length > 0)
            {
                radMultiColumnComboBox.Text = currentText;
            }
        }

 

dvBrand consists of columns PKBrand(Int datatype in SQL), BrandName is varchar type in sql. In RadMultiColumnComboBox column collection also defined with column PKBrand(System.Int32 type) and BrandName (System.String type)

           
Justine
Top achievements
Rank 1
commented on 21 Mar 2023, 01:04 PM

After binding the control with the datasource, displaymember and valuemember, we are calling another method to assign the selectedvalue of the RadMultiColumnComboBox control and the code is given below.

public static string MultiColumnComboSetValue(Telerik.WinControls.UI.RadMultiColumnComboBox control, string columnName, string columnValue) //VW-5635
        {
            string ErrMsg = "";
            if (string.IsNullOrWhiteSpace(columnValue) || columnValue == "-1")//VW-5635
            {
                control.SelectedIndex = -1;
                ErrMsg = "Value Required";
            }
            else
            {
                DataTable dtMultiColumnSource = new DataTable();
                // dtMultiColumnSource = (DataTable)control.DataSource;
                if (control.DataSource != null)
                {
                    if (((DataView)control.DataSource).Count > 0)
                    {
                        dtMultiColumnSource = ((DataView)control.DataSource).ToTable();
                        DataTable dtTemp = new DataTable();
                        dtTemp = dtMultiColumnSource.Copy();
                        DataRow[] drselectedItem = dtTemp.Select($"{columnName } = {columnValue}");
                        if (drselectedItem != null && drselectedItem.Length > 0)
                        {
                            int selectedIndex = dtTemp.Rows.IndexOf(drselectedItem[0]);
                            control.SelectedIndex = selectedIndex;
                        }
                        else
                        {
                            control.SelectedIndex = -1;
                        }
                    }
                }
            }
            return ErrMsg;
        }

 

And we are getting error from this line 'control.SelectedIndex = selectedIndex;' with error message as

System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index'

at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
   at Telerik.WinControls.UI.RadMultiColumnComboBoxElement.set_SelectedIndex(Int32 value)
   at Telerik.WinControls.UI.RadMultiColumnComboBox.set_SelectedIndex(Int32 value)
   at XYZ.Client.ClientHelper.MultiColumnComboSetValue(RadMultiColumnComboBox control, String columnName, String columnValue)
Dess | Tech Support Engineer, Principal
Telerik team
commented on 22 Mar 2023, 02:09 PM

Hello, Justine,

According to the provided information, it seems that the SelectedIndex property is set to an invalid value. In other words, RadMultiColumnComboBox 
doesn't contain such a number of rows and a record at such an index doesn't exist. Please correct me if I am wrong. It is not clear what are the available rows in the popup grid and how many records are filtered. Could you please elaborate?

It is important to note that the composite filters allow you to create more complex filtering expressions. This feature is supported for text columns only as the RadMultiColumnComboBox has one common text input for the filtering operation and it is not possible to convert input data to different data formats automatically.

I have attached my sample project. Please give it a try and see how it works on your end. Am I missing something? Could you please specify the exact steps how to reproduce the problem?

Tags
MultiColumn ComboBox
Asked by
Jihad
Top achievements
Rank 1
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or