Set GridviewComboBox to Null

4 posts, 1 answers
  1. Steven
    Steven avatar
    5 posts
    Member since:
    Dec 2013

    Posted 17 Dec 2013 Link to this post

    Is it possible to set a combobox column to null?  I currently have the following shell of code:

    private void RadGV_Records_KeyDown(object sender, KeyEventArgs e)
            {
                if (RadGV_Records.CurrentColumn.GetType().ToString() == "Telerik.WinControls.UI.GridViewComboBoxColumn")
                {
                    if (e.KeyCode == Keys.Delete)
                    {
                       
                        
                    }
                }
            }

    Inside the "if (e.KeyCode == Keys.Delete)", I want to set the current combobox value to null or empty, like it is before the user selects anything from the box.
  2. Answer
    Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4086 posts

    Posted 20 Dec 2013 Link to this post

    Hello Steven,

    Thank you for contacting Telerik Support.

    In order to achieve your goal, it is necessary to implement custom GridDataRowBehavior and change the default behavior for the ProcessDeleteKey method as follows:
    public Form1()
    {
        InitializeComponent();
        
        List<Status> statuses = new List<Status>()
        {
            new Status(1,"Not done"),
            new Status(2,"Done"),
            new Status(3,"In progress"),
            new Status(4,"Ready for test"),
        };
     
        Random rand = new Random();
        List<GridItem> dataSource = new List<GridItem>();
        for (int i = 0; i < 5; i++)
        {
            dataSource.Add(new GridItem(i,"Name" + i,statuses[rand.Next(0, statuses.Count)].Title));
        }
         
        GridViewDecimalColumn decimalColumn = new GridViewDecimalColumn("Id");
        radGridView1.MasterTemplate.Columns.Add(decimalColumn);
     
        GridViewTextBoxColumn textBoxColumn = new GridViewTextBoxColumn("Name");
        radGridView1.MasterTemplate.Columns.Add(textBoxColumn);
     
        GridViewComboBoxColumn statusColumn = new GridViewComboBoxColumn("CurrentStatus");
        statusColumn.DataSource = statuses;
        statusColumn.DisplayMember = "Title";
        radGridView1.Columns.Add(statusColumn);
     
        radGridView1.AutoGenerateColumns = false;
        radGridView1.DataSource = dataSource;
     
        BaseGridBehavior gridBehavior = this.radGridView1.GridBehavior as BaseGridBehavior;
        gridBehavior.UnregisterBehavior(typeof(GridViewDataRowInfo));
        gridBehavior.RegisterBehavior(typeof(GridViewDataRowInfo), new CustomGridBehavior());
    }
     
    public class GridItem
    {
        public int Id { get; set; }
     
        public string Name { get; set; }
     
        public string CurrentStatus { get; set; }
     
        public GridItem(int id, string name, string currentStatus)
        {
            this.Id = id;
            this.Name = name;
            this.CurrentStatus = currentStatus;
        }
    }
     
    public class Status
    {
        public int Code { get; set; }
     
        public string Title { get; set; }
         
        public Status(int code, string title)
        {
            this.Code = code;
            this.Title = title;
        }
    }
     
    public class CustomGridBehavior : GridDataRowBehavior
    {
        protected override bool ProcessDeleteKey(KeyEventArgs keys)
        {
            if (this.GridControl.CurrentCell is GridDataCellElement &&
                this.GridControl.CurrentColumn is GridViewComboBoxColumn)
            {
                this.GridControl.CurrentCell.Value = string.Empty;
                return true;
            }
            return base.ProcessDeleteKey(keys);
        }
    }

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. Steven
    Steven avatar
    5 posts
    Member since:
    Dec 2013

    Posted 06 Jan 2014 Link to this post

    Thank you... I was able to use what you provided and make it into a solution that will work for this project!
  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4086 posts

    Posted 08 Jan 2014 Link to this post

    Hello Steven,

    Thank you for writing back.

    I am glad that the issue you were facing is now resolved. Please do not hesitate to contact us if you have any additional questions.

    It was pleasure for me to assist you.

    Regards,
    Desislava
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top