[Mono-bugs] [Bug 811232] New: DataGridViewComboboxColumn does not respect DisplayMember when adding new rows programatically

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Mar 24 11:45:44 UTC 2013


https://bugzilla.novell.com/show_bug.cgi?id=811232

https://bugzilla.novell.com/show_bug.cgi?id=811232#c0


           Summary: DataGridViewComboboxColumn does not respect
                    DisplayMember when adding new rows programatically
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.10.x
          Platform: All
        OS/Version: Ubuntu
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Windows.Forms
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: lord.of.the.trains at centrum.cz
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


Created an attachment (id=531355)
 --> (http://bugzilla.novell.com/attachment.cgi?id=531355)
Test project containing a WinForms application with mentioned test cases.

User-Agent:       Mozilla/5.0 (Windows NT 6.0; rv:19.0) Gecko/20100101
Firefox/19.0

Situation: DataGridViewComboboxColumn uses a list of objects as its items. Such
object has for example an int property representing actual value and string
property representing what should be shown to the user.
DataGridViewComboboxColumn has DisplayMember and ValueMember properties
correctly set.

Problem: when I programatically add a row to the DataGridView, and I specify a
correct int value for the combo column, this int value is shown in the grid
instead of the corresponding string value.
Note: expected behavior works in Mono for ordinary comboboxes (setting
SelectedValue shows value specified by DisplayMember).

This works as expected when running on Windows with MS .NET runtime, but when
running under Mono on Ubuntu it shows described behavior.
Note: I think it is not specific to operating system, but I didn't test it
under Mono on Windows, so I can't tell.

I have developed a test project to show this behavior, I will add it as an
attachment. It's a simple WinForms application, project can be built using
either Visual Studio or MonoDevelop.
There are 3 test cases:
1) no databinding, combo column uses Items property as the source of available
items;
2) combo column is data-bound to a BindingSource object, DataGridView itself is
not data-bound;
3) whole DataGridView is bound to a DataTable, combo column is bound to another
DataTable (typical scenario for displaying data from tables with foreign keys).


Reproducible: Always

Steps to Reproduce:
// An excerpt from the first test case.

// Class representing items available in the combo column.
class ComboItem
{
    public string DisplayValue { get; set; } // the value that should be shown
    public int RealValue { get; set; } // the actual value
    public ComboItem(string iDisplayValue, int iValue)
    {
        DisplayValue = iDisplayValue;
        RealValue = iValue;
    }
}

// Setup the DGV and combo column like this...
DataGridView DGV1 = new DataGridView();
DataGridViewComboBoxColumn lColumn = new DataGridViewComboBoxColumn();
lColumn.Items.Add(new ComboItem("A", 1));
lColumn.Items.Add(new ComboItem("B", 2));
lColumn.DisplayMember = "DisplayValue";
lColumn.ValueMember = "RealValue";
DGV1.Columns.Add(lColumn);

// Now add a row with value 1 in the combo column. It should show value 'A' in
it.

object[] lData = new object[1] { (int) 1 };
DGV1.Rows.Add(lData);

Actual Results:  
On Mono, value '1' is displayed in the column. On MS runtime, value 'A' is
displayed (which is expected).

Expected Results:  
Value 'A' should be displayed.

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list