Adding items into GridViewComboBox Column

3 posts, 0 answers
  1. Empanada
    Empanada avatar
    6 posts
    Member since:
    Sep 2011

    Posted 02 Oct 2011 Link to this post

    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. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 03 Oct 2011 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 03 Oct 2011 Link to this post

    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 >>

Back to Top