How to add a blank or empty row?

8 posts, 0 answers
  1. Ryan
    Ryan avatar
    13 posts
    Member since:
    May 2010

    Posted 15 May 2012 Link to this post

    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
  2. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 18 May 2012 Link to this post

    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 >>
  3. Ryan
    Ryan avatar
    13 posts
    Member since:
    May 2010

    Posted 28 May 2012 Link to this post

    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
  4. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 30 May 2012 Link to this post

    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 >>
  5. Ryan
    Ryan avatar
    13 posts
    Member since:
    May 2010

    Posted 31 May 2012 Link to this post

    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
  6. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 05 Jun 2012 Link to this post

    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 >>
  7. Ahmed
    Ahmed avatar
    2 posts
    Member since:
    Aug 2019

    Posted 06 Aug Link to this post

    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

  8. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3321 posts

    Posted 08 Aug Link to this post

    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.
Back to Top