Bind visible column ComboBox to DataTable

Hello,

In my GridDataControl I have a combobox type column which I would like to bind to a datatable.

I've tried this with no success:

var _eventTypes = from g in GlobalData.db.EventTypes select new { g.EventTypeID, g.EventTypeDesc };
DataTable dtEvents = new DataTable();
DataColumn column; DataColumn column2;
column = new DataColumn(); column2 = new DataColumn();

column.ColumnName = "EventTypeID";
column2.ColumnName ="EventTypeDesc";
column2.DataType = System.Type.GetType("System.String");
column.DataType = System.Type.GetType("System.Int32");
dtEvents.Columns.Add(column);
dtEvents.Columns.Add(column2);

foreach (var o in _eventTypes)
{
// dicEventType.Add(o.EventTypeDesc, o.EventTypeID);
DataRow row = dtEvents.NewRow();
row[0] = int.Parse(o.EventTypeID.ToString());
row[1] = o.EventTypeDesc;
dtEvents.Rows.Add(row);
}


int test = dtEvents.Rows.Count;

this.grdEventsUpload.VisibleColumns["EventType"].ColumnStyle.ItemsSource = dtEvents;
this.grdEventsUpload.VisibleColumns["EventType"].ColumnStyle.ValueMember = "EventTypeID";
this.grdEventsUpload.VisibleColumns["EventType"].ColumnStyle.DisplayMember = "EventTypeDesc";

I'm not getting any errors but the combobox items list is empty.

thanks



1 Reply

DM Deenadhayalan M Syncfusion Team June 22, 2011 07:25 PM UTC

Hi Assaf,

Thanks for your interest in Syncfusion products.

We have prepared a sample based on your code snippet and achieved your requirement. Please find the sample under the following location.

Please let us know if this sample helps.

Regards,
Deenadhayalan



Combobox_Database_dadf61c0.zip

Loader.
Up arrow icon