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

How to add a blank or empty row?

7 Answers 1366 Views
MultiColumn ComboBox
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 15 May 2012, 09:33 PM
Hello,

We're currently using a radmulticolumncombobox populated through a dataset, and need the capability of selecting a blank row. Within our database the field it refers to is non-null, and the client has to be able to select nothing for a value.

I've tried using lstParentGroup.EditorControl.Rows.AddNew(), but this adds the row to the very bottom of the collection. We definitely want the blank row at the top of the list. Also, when this row is added, the control seems to get confused when using lstParentGroup.SelectedValue functionality. What happens is the blank row at the bottom is selected instead of what should be selected.

Anything I've missed in the designer, or possible solutions to this problem?

Thank you very much for your time!
Ryan

7 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 18 May 2012, 03:01 PM
Hi Ryan,

Thank you for writing.

You can add dummy row in your DataSource and pin the related GridViewRowInfo instance to the top in order to achieve your scenario. Here is a sample application with DataTable binding and the event handler implementation:
using System;
using System.Data;
using Telerik.WinControls.UI;
 
namespace Lab.Combo
{
    public partial class MultiComboEmptyRow : MainForm
    {
        private RadMultiColumnComboBox comboBox = new RadMultiColumnComboBox();
        private DataRow emptyRow;
        public event EventHandler NoneSelected;
 
        public MultiComboEmptyRow()
        {
            InitializeComponent();
 
            comboBox.Parent = this;
            comboBox.SelectedIndexChanged += comboBox_SelectedIndexChanged;
 
        }
 
        void comboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewRowInfo current = this.comboBox.EditorControl.CurrentRow;
            if (current != null)
            {
                DataRow row = (current.DataBoundItem as DataRowView).Row;
                if (row == emptyRow && this.NoneSelected != null)
                {
                    this.NoneSelected(this, new EventArgs());
                }
            }
        }
 
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
 
            DataTable table1 = new DataTable();
            table1.Columns.Add("ID");
            table1.Columns.Add("Name");
 
            this.emptyRow = table1.Rows.Add(null, null);
 
            table1.Rows.Add(1, "Ivan Petrov");
            table1.Rows.Add(2, "Stefan Muler");
            table1.Rows.Add(3, "Alexandro Ricco");
 
            this.comboBox.DataSource = table1;
            comboBox.DisplayMember = "Name";
 
            SetTopEmptyRow();
        }
 
        private void SetTopEmptyRow()
        {
            foreach (GridViewRowInfo row in this.comboBox.EditorControl.Rows)
            {
                if ((row.DataBoundItem as DataRowView).Row == this.emptyRow)
                {
                    row.PinPosition = PinnedRowPosition.Top;
                    break;
                }
            }
        }
    }
}

I hope this helps.

Regards,
Julian Benkov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Ryan
Top achievements
Rank 1
answered on 28 May 2012, 07:56 AM
Hi Julian,

Thanks for your reply so far.

The main problem is that my combobox is already databound through a table adapter. I can create the new row and pin it to the top, but when it comes time to fill the table adapter again, Object Reference exceptions are raised because of the blank row. I can remove the row before filling then add it again, but this leads to a unique problem where two blank rows exist.

Thanks for your help
0
Julian Benkov
Telerik team
answered on 30 May 2012, 04:30 PM
Hello Ryan,

In this situation, you should remove the row from the PinPosition:

this.gridView.Rows[0].PinPosition = PinnedRowPosition.None;

After that remove the row from the DataSource object and fill the DataSouce. Then you can add the empty row again and pin to top position.

I hope this helps.

Kind regards,
Julian Benkov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Ryan
Top achievements
Rank 1
answered on 31 May 2012, 10:45 PM
Here is the final solution for me:

Dim emptyRow As Telerik.WinControls.UI.GridViewRowInfo
 
                    If emptyRow IsNot Nothing Then
                        emptyRow.PinPosition = PinnedRowPosition.None
                    End If
                    Dim rows As New List(Of GridViewRowInfo)(Me.lstParentGroup.EditorControl.Rows)
                    If rows.Any Then
                        For Each row As Telerik.WinControls.UI.GridViewDataRowInfo In rows
                            row.Delete()
                        Next
                    End If
                    GroupByJobTableAdapter.FillByJobID(DataMain.GroupByJob, lstJob.SelectedValue)
                    emptyRow = lstParentGroup.EditorControl.Rows.AddNew()
                    emptyRow.PinPosition = PinnedRowPosition.Top
                    emptyRow.Cells("GroupNo").Value = "None"

Thank you very much for you help!

Cheers,
Ryan
0
Julian Benkov
Telerik team
answered on 05 Jun 2012, 09:54 AM
Hello Ryan,

I am glad to hear that you have solved your issue. 

Feel free to ask if you have any additional questions. 

Greetings,
Julian Benkov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Ahmed
Top achievements
Rank 1
answered on 06 Aug 2019, 05:38 PM

Hi!

I'm having the same issue. When i load data from Query into MultiColumnCB, and update the data by selecting from it. When i have last value left in MultiColumnCB, no index is changed. If there is another solution for it then i would appreciate. If not, then i will add an empty row for this to change the index and make the rest code work. 

My code is:

 

    Private Sub FwdDocQuery_SelectedIndexChanged(sender As Object, e As EventArgs) Handles FwdDocQuery.SelectedIndexChanged

        StatusIDRadTextBox1.Text = "2"
        If Not String.IsNullOrWhiteSpace(FwdDocQuery.Text) Then
            Dim index As Integer = ApplicationsBindingSource.Find("ID", FwdDocQuery.Text)
            If index > -1 Then
                ApplicationsBindingSource.Position = index
            End If
        End If
        If DocTypeIDRadTextBox1.Text = "1" Then
            DocTypeTBFWD.Text = "Transcript"
        ElseIf DocTypeIDRadTextBox1.Text = "2" Then
            DocTypeTBFWD.Text = "Degree"
        ElseIf DocTypeIDRadTextBox1.Text = "3" Then
            DocTypeTBFWD.Text = "NOC"
        End If

    End Sub

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 08 Aug 2019, 01:42 PM
Hello, Ahmed, 

If you need to delete the value in RadMultiColumnComboBox, simply press the Delete key while the editable part is focused. Thus, when you navigate the next control on the form, no value will be selected in RadMultiColumnComboBox.

Indeed, adding an empty row to the DataTable that is used for DataSource in RadMultiColumnComboBox is an appropriate solution to offer the user an option for selecting in the drop down. Thus, when you select the empty record, there is a dedicated value for it with an empty DisplayMember.

I hope this information helps. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
MultiColumn ComboBox
Asked by
Ryan
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Ryan
Top achievements
Rank 1
Ahmed
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or