Home Forums WinForms controls Xceed Grid for WinForms Problem with GridComboBox boxes.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #12737 |

    I have a problem that I just can’t seem to sort out. I have two columns of a databound Xceed datagrid for .Net that I want to display with the GridComboBox boxes.

    The problem is that the first one works just fine, the second doesn’t. The second one has the data in it, but for some reason, after selection happens, the ValueMember is displayed instead of the DisplayMember like it should. When I click the down arrow to make a selection, I see all the DisplayMembers like I should. The problem is after done editing, the ValueMember is displayed in the cell, not the DisplayMember.

    Remember, I am adding two of these columns to the same grid, the first works just fine. The code for the second one is the exact same except for the necessary changes for datasource, displaymember, and valuemember.

    I get no errors thrown, and I know it is doing something, it just isn’t registering the CellViewer or something. I tried recreating the problem in a seperate solution, but wow, it worked perfectly. So there is something funky going on. I deleted the grid, and added a new one to the form again. Renamed it. Nothing worked. I changed up the order of the code also. I commented out all the code except the actual retrieval of data, and the code below. It still didn’t fix it.

    PLEASE tell me there is something simple I can do.

    Here is the code (m_dtDependants contains the main data , m_dtVerified and m_dtVerifiedByEmployee are the lookup tables for the gridcombobox’s. All three are datatables that have data in them.)

    Dim gridComboBox1 As Xceed.Grid.Editors.GridComboBox = New Xceed.Grid.Editors.GridComboBox
    Dim gridComboBox2 As Xceed.Grid.Editors.GridComboBox = New Xceed.Grid.Editors.GridComboBox

    XceedPatronGrid.DataSource = m_dtDependants

    ‘ Create a grid combo box for verification type
    gridComboBox1.DisplayMember = “VerificationType”
    gridComboBox1.ValueMember = “VerificationTypeID”
    gridComboBox1.DataSource = m_dtVerified
    XceedPatronGrid.Columns(“VerificationTypeID”).CellEditor = gridComboBox1
    XceedPatronGrid.Columns(“VerificationTypeID”).CellViewer = gridComboBox1

    ‘ Create a grid combo box for verified by
    gridComboBox2.DisplayMember = “Employee”
    gridComboBox2.ValueMember = “EmployeeID”
    gridComboBox2.DataSource = m_dtVerifiedByEmployee
    XceedPatronGrid.Columns(“VerifiedByID”).CellViewer = gridComboBox2
    XceedPatronGrid.Columns(“VerifiedByID”).CellEditor = gridComboBox2

    Imported from legacy forums. Posted by hellswraith (had 6007 views)

    User (Old forums)
    Member
    Post count: 23064

    I used to have this problem too: in my project, the problem was that the Type of the GridColumn and the ComboBox-ValueMember were not the same: the one was an Int32 and the other was a String.

    Perhaps this is the same in your project.

    Imported from legacy forums. Posted by Tommy (had 273 views)

    User (Old forums)
    Member
    Post count: 23064

    Your point makes sense. However, how do you show the display member to the user and use the value member to update your datatable?

    I hope that makes sense to you.

    ACanadian

    Imported from legacy forums. Posted by ACanadian (had 279 views)

    User (Old forums)
    Member
    Post count: 23064

    The DisplayMember can be any type you want to (preferably string), the ValueMember has to be of the same type is the DataTable-field.

    Grid1 : DataSource/DataMember = DataTable1
    DataTable1 has field DataField1
    DataField1 in Grid1 : editor & viewer = GridComboBox1
    GridComboBox1 : DataSource/DataMember = DataTable2
    DataTable2 has fields DataFieldValue & DataFieldDisplay
    GridComboBox1.ValueMember = DataFieldValue
    GridComboBox1.DisplayMember = DataFieldDisplay

    Voorwaarden: typeof(DataFieldValue) == typeof(DataField1)

    Imported from legacy forums. Posted by Tommy (had 243 views)

    User (Old forums)
    Member
    Post count: 23064

    That solution works very nicely. But what about this… 😉

    Your datagrid is bound to a datatable. And in my case the DataFieldValue is an Id to mantian referential integrity. And I don’t really like using strings for my id columns.

    So DataField1 is bound to a column in a datatable of type System.Int

    Solution (Though painfull)

    Create a two columns. One bound and one unbound.
    Column 1(invisible) is bound to the datatable column
    Column2(visible) is unbound and of type System.String

    Column1 has default cell view and editors.
    Column2 will use GridComboBox1 for view and edit.

    (Fun part)
    When the value of Column2 changes, set the value of Column1

    (When the grid is done loading)
    Populate column2

    viola

    It works but there has to be a better way

    ACanadian

    Imported from legacy forums. Posted by ACanadian (had 289 views)

    User (Old forums)
    Member
    Post count: 23064

    How about this problem shouldn’t have to be worked around in the first place!

    I have tried what each of you have said. No luck. Both gridcomboboxes I am using use the same table structure from the database. This is just rediculous.

    Check this out, the problem still persists when I do this:
    Original code with errors:
    ‘ Create a grid combo box for verified by
    gridComboBox2.DataSource = m_dtVerifiedByEmployee
    gridComboBox2.DisplayMember = “Employee”
    gridComboBox2.ValueMember = “EmployeeID”
    XceedPatronGrid.Columns(“VerifiedByID”).CellEditor = gridComboBox2
    XceedPatronGrid.Columns(“VerifiedByID”).CellViewer = gridComboBox2

    ‘Create a grid combo box for verification type
    gridComboBox1.DataSource = m_dtVerified
    gridComboBox1.DisplayMember = “VerificationType”
    gridComboBox1.ValueMember = “VerificationTypeID”
    XceedPatronGrid.Columns(“VerificationTypeID”).CellEditor = gridComboBox1
    XceedPatronGrid.Columns(“VerificationTypeID”).CellViewer = gridComboBox1

    Changed it to this (Made the display member and value member the same as the other combo box that is working):
    ‘ Create a grid combo box for verified by
    gridComboBox2.DisplayMember = “VerificationType”
    gridComboBox2.ValueMember = “VerificationTypeID”
    gridComboBox2.DataSource = m_dtVerified
    XceedPatronGrid.Columns(“VerifiedByID”).CellViewer = gridComboBox2
    XceedPatronGrid.Columns(“VerifiedByID”).CellEditor = gridComboBox2

    ‘ Create a grid combo box for verification type
    gridComboBox1.DisplayMember = “VerificationType”
    gridComboBox1.ValueMember = “VerificationTypeID”
    gridComboBox1.DataSource = m_dtVerified
    XceedPatronGrid.Columns(“VerificationTypeID”).CellEditor = gridComboBox1
    XceedPatronGrid.Columns(“VerificationTypeID”).CellViewer = gridComboBox1

    Notice that both gridcomboboxes are using the same datasource, displaymember, and valuemembers. The VerificationTypeID column displays the right way, and teh VerifiedByID doesn’t still. So we can eliminate the datasources for the grid combo boxes as being the cause.

    This is a huge problem for me as my deadline approaches.

    Imported from legacy forums. Posted by hellswraith (had 493 views)

    User (Old forums)
    Member
    Post count: 23064

    Ok, time to eat my own words.

    I figured out that the underlying types were different, as said above. I hadn’t explored all possible avenues to totally check it out before.

    Sorry for the ranting, I have been in a rage over this for quite a while now.

    Imported from legacy forums. Posted by hellswraith (had 644 views)

    User (Old forums)
    Member
    Post count: 23064

    Hey hellswraith,

    I solved this problem awhile ago. It seems that there is only one way to attach your data source for the combo box to work correctly.

    cboPhoneNumberTypes.DataSource = ds.Tables[“tblPhoneNumberTypes_ManageContact”];
    cboPhoneNumberTypes.DisplayMember = “PhoneNumberType”;
    cboPhoneNumberTypes.ValueMember = “PhoneNumberTypeId”;

    I could only get it to work by assign the datasource via the table collection of a data set.

    Hope this helps,

    ACanadian

    Imported from legacy forums. Posted by ACanadian (had 6892 views)

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.