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

Set GridviewComboBox to Null

3 Answers 45 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 17 Dec 2013, 10:10 PM
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.

3 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 20 Dec 2013, 02:31 PM
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 >>
0
Steven
Top achievements
Rank 1
answered on 06 Jan 2014, 06:30 PM
Thank you... I was able to use what you provided and make it into a solution that will work for this project!
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 08 Jan 2014, 03:38 PM
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 >>
Tags
GridView
Asked by
Steven
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Steven
Top achievements
Rank 1
Share this question
or