We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

DataBoundGrid ComboBox Value- and Display-Members

Hi,

I have a griddatacontrol bound to a DataTable object. One of the datatable columns holds an Int32-Value indicating a status of the row entry.

I managed to display a ComboBox in the column showing this state-Value from an StringCollection:

<syncfusion:GridDataVisibleColumn.ColumnStyle>

<syncfusion:GridDataColumnStyle CellType="ComboBox" DropDownStyle="Exclusive">

</syncfusion:GridDataColumnStyle>

...

StringCollection exampleList = new StringCollection();

exampleList.Add("One");

exampleList.Add("Two");

exampleList.Add("Three");

this.m_dbGrid.VisibleColumns["Wert-Typ"].ColumnStyle.ItemsSource = exampleList;

m_dbGrid.ItemsSource = m_oKommClient.m_dbNormName;

My problem is now, that I can select the Values from the collection in the grid (e.g. One, Two, Three) but bound to the database is the index (e.g. 0, 1, 2). So my selection of the comboboxstring would result in an format exception.

<see attachement>

How can I tell the grid the bind to the values and to diplay the names?

Similar to ComboBox.DisplayMember and ComboBox.ValueMember...

Thanks in advance!

Martin

 

 



test_3b043ed9.zip

1 Reply

GA Gobinath A Syncfusion Team March 7, 2013 11:26 AM UTC

Hi Martin,

Sorry for the delay caused.

We have analyzed your query and You can set the display member by using below the code snippet.

Code snippet[XAML]:

<sf:GridDataColumnStyle CellType="ComboBox" DisplayMember="DisplayString" ValueMember="Number"/>

Code snippet [C#]:

List<Item> exampleList = new List<Item>();

exampleList.Add(new Item() { DisplayString = "Thousand", Number = 10000 });

exampleList.Add(new Item() { DisplayString = "Thousand One", Number = 10001 });

exampleList.Add(new Item() { DisplayString = "Thousand Two", Number = 10002 });

exampleList.Add(new Item() { DisplayString = "Thousand Three", Number = 10003 });

exampleList.Add(new Item() { DisplayString = "Thousand Four", Number = 10004 });

Sample: WpfApplication1.zip

Please let us know if this helps.

Regards,

Gobinath A.


Loader.
Up arrow icon