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

Adding items into GridViewComboBox Column

2 Answers 85 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Empanada
Top achievements
Rank 1
Empanada asked on 02 Oct 2011, 07:46 AM
Hi Guys,
I have a GridViewTexboxColumn that displays Gender ( either M or F ) and I want to change it into GridViewComboBox that has 2 items, Male and Female
Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 03 Oct 2011, 07:15 AM
Hello,

First, you need to handle the DataBindingComplete event
void radGridView_DataBindingComplete(object sender, GridViewBindingCompleteEventArgs e)
{
    var grid = sender as RadGridView;
    if (grid == null || !grid.Columns.Contains("Gender"))
    {
        return;
    }
 
    grid.Columns.Remove("Gender");
 
    var genderColumn = new GridViewComboBoxColumn("Gender")
                           {
                               DataSource = new List<GenderHelper> { new GenderHelper("Male", "M"), new GenderHelper("Female", "F") },
                               DisplayMember = "Display",
                               ValueMember = "Value"
                           };
    grid.Columns.Add(genderColumn);
}
 
public class GenderHelper
{
    public string Display { get; set; }
    public string Value { get; set; }
 
    public GenderHelper(string display, string value)
    {
        Display = display;
        Value = value;
    }
}

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

Telerik WinForms MVP
0
Ivan Petrov
Telerik team
answered on 03 Oct 2011, 11:41 AM
Hello Empanada,

Thank you for writing.

The solution provided by Emanuel is the right approach in this situation. If this has helped you, please mark his post as an answer so others can find the solution to their issues easier. 

Should there be anything else, do not hesitate to write back.

Greetings,
Ivan Petrov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Empanada
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Ivan Petrov
Telerik team
Share this question
or