Forums

GridViewDataComboBoxColumn shows GUID instead of TextField Value

Last post 11/19/2009 10:43 PM by Trevor Munn. 7 replies.
Sort Posts: Previous Next
  • Trevor Munn

    GridViewDataComboBoxColumn shows GUID instead of TextField Value

    6/25/2009 2:54 AM
    • Not Ranked
    • Joined on 6/4/2009
    • Posts 6

    Hi

    I'm a bit new to this but am having a problem with a combo column I have added.  It seems to work fine (TextField value is showing in grid, filter dropdown is displaying TextValue values and filtering is working), until I go to edit a row.

    When I do the dropdown in the edit form shows the guid value as selected, selecting any other value will fix the problem, it will show the Text of whatever item I select, clicking save will also work and update the grid field with the new value.  If I hit edit again (on this or any other row) the guid is shown again.

    Problem as seen when clicking edit

    Markup for the column looks like this:

     

    <dxwgv:GridViewDataComboBoxColumn FieldName="RoleId"

                    VisibleIndex="2" Caption="<%$ Resources: GridColumn.Role.Title %>">

                    <PropertiesComboBox ValueType="System.Guid" ValueField="RoleId" TextField="RoleName">

                        <ValidationSettings>

                            <RequiredField IsRequired="True" />

                        </ValidationSettings>

                    </PropertiesComboBox>

                </dxwgv:GridViewDataComboBoxColumn>

    And the datasource for the combo is set during DataBinding like so:

     

    protected override void OnInit(EventArgs e)

        {

            base.OnInit(e);

            ASPxGridView1.DataBinding += new EventHandler(ASPxGridView1_DataBinding);

            ASPxGridView1.RowInserting += new DevExpress.Web.Data.ASPxDataInsertingEventHandler(ASPxGridView1_RowInserting);

            ASPxGridView1.RowUpdating += new DevExpress.Web.Data.ASPxDataUpdatingEventHandler(ASPxGridView1_RowUpdating);

        }

     

    void ASPxGridView1_DataBinding(object sender, EventArgs e)

        {

            GridViewDataComboBoxColumn column = ((GridViewDataComboBoxColumn)(sender as ASPxGridView).Columns["RoleId"]);

            column.PropertiesComboBox.DataSource = (List<RoleInfo>)Session["RoleComboBoxDataSource"];

            column.PropertiesComboBox.TextField = "RoleName";

            column.PropertiesComboBox.ValueField = "RoleId";

        }

     

     

     

    Not sure whether it makes a difference but the grid itself is also populated without a DataSourceID:

    protected void Page_Load(object sender, EventArgs e)

        {

            DataBind();

        }

    public void DataBind()

        {

            if (Session["GroupList"] == null) GetDataSource();

            List<GroupInfo> list = (List<GroupInfo>)Session["GroupList"];

            ASPxGridView1.DataSource = list;

            ASPxGridView1.KeyFieldName = "GroupId";

            ASPxGridView1.AutoGenerateColumns = true;

            ASPxGridView1.EnableRowsCache = false;

            ASPxGridView1.DataBind();

        }

  • Sagest Ekonomi

    Re: GridViewDataComboBoxColumn shows GUID instead of TextField Value

    6/25/2009 3:16 AM
    • Not Ranked
    • Joined on 4/10/2009
    • Posts 27

    One solution that works fine for me is this :

    In the ASPxGridView1_DataBinding event add this code :

    (sender as ASPxGridView).Remove((sender as ASPxGridView).Columns["RoleId"]);
    GridViewDataComboBoxColumn column =new 
    GridViewDataComboBoxColumn();
    column.FieldName = "RoleId";
    column.PropertiesComboBox.DataSource = (List<RoleInfo>)Session["RoleComboBoxDataSource"];
    column.PropertiesComboBox.TextField = "RoleName";
    column.PropertiesComboBox.ValueField = "RoleId";
    (sender as ASPxGridView).Columns.Add(column);

  • Trevor Munn

    Re: GridViewDataComboBoxColumn shows GUID instead of TextField Value

    6/25/2009 3:39 AM
    • Not Ranked
    • Joined on 6/4/2009
    • Posts 6

    Made no difference unfortunately.

    I can't really see why removing and adding the column would help.

    Thanks for trying to help though.

    Smile

  • Bob Lan

    Re: GridViewDataComboBoxColumn shows GUID instead of TextField Value

    7/12/2009 11:35 PM
    • Not Ranked
    • Joined on 6/22/2009
    • Posts 9

     I met the same problem!!

  • Stuart Duncan

    Re: GridViewDataComboBoxColumn shows GUID instead of TextField Value

    7/14/2009 10:50 AM
    • Top 150 Contributor
    • Joined on 7/30/2007
    • Posts 124

    Try setting the properties of the combobox in the CellEditorInitialize event instead.

  • Trevor Munn

    Re: GridViewDataComboBoxColumn shows GUID instead of TextField Value

    11/19/2009 8:37 PM
    • Not Ranked
    • Joined on 6/4/2009
    • Posts 6

    Using the CellEditorInitialize event didn't work either.

  • Bob Lan

    Re: GridViewDataComboBoxColumn shows GUID instead of TextField Value

    11/19/2009 9:23 PM
    • Not Ranked
    • Joined on 6/22/2009
    • Posts 9
    Answer

    It works for me:

            protected void DataGrid_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e)
            {
                if (e.Column.FieldName == "MyGuid")
                {
                    Guid key = new Guid(e.Value.ToString());
                    ASPxComboBox combobox = (ASPxComboBox)e.Editor;
                    for (int i = 0; i < combobox.Items.Count; i++)
                    {
                        if (key == (Guid)combobox.Items[i].Value)
                        {
                            combobox.SelectedIndex = i;
                            break;
                        }
                    }
                }
            }

  • Trevor Munn

    Re: GridViewDataComboBoxColumn shows GUID instead of TextField Value

    11/19/2009 10:43 PM
    • Not Ranked
    • Joined on 6/4/2009
    • Posts 6

    That's done the trick.  Didn't realise I needed existing DataBinding code as well as selected item selection on CellEditorInitialize.

    Thanks so much Big Smile

More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.