in
Forums
Blogs
DevExpress.com
Client Center
Support Center
DevExpress Channel

GridViewDataComboBoxColumn shows GUID instead of TextField Value

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

    GridViewDataComboBoxColumn shows GUID instead of TextField Value

    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();

        }

  • 6/25/2009 3:16 AM In reply to

    Re: GridViewDataComboBoxColumn shows GUID instead of TextField Value

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

  • 6/25/2009 3:39 AM In reply to

    Re: GridViewDataComboBoxColumn shows GUID instead of TextField Value

    Made no difference unfortunately.

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

    Thanks for trying to help though.

    Smile

  • 7/12/2009 11:35 PM In reply to

    Re: GridViewDataComboBoxColumn shows GUID instead of TextField Value

     I met the same problem!!

  • 7/14/2009 10:50 AM In reply to

    Re: GridViewDataComboBoxColumn shows GUID instead of TextField Value

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

  • 11/19/2009 8:37 PM In reply to

    Re: GridViewDataComboBoxColumn shows GUID instead of TextField Value

    Using the CellEditorInitialize event didn't work either.

  • 11/19/2009 9:23 PM In reply to

    Re: GridViewDataComboBoxColumn shows GUID instead of TextField Value

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

  • 11/19/2009 10:43 PM In reply to

    Re: GridViewDataComboBoxColumn shows GUID instead of TextField Value

    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

Copyright © 1998-2010 Developer Express Inc.
ALL RIGHTS RESERVED