Anjali
Anjali

Reputation: 1718

How to assign Data to Datatable with Combobox Datasource?

I am binding data to combobox with a datatable(dt1) in a method called IsDatafill.

combobox.DataSource=dt1;
combobox.DisplayMember="Col_1";
combobox.ValueMember="Col_2";

and bringing some more data with that datatable(dt1) like col_3,col_4; so i use this data in another event is selectedIndexChanged event. so here i have a datatable(dt2). here i want to assign data to this by using

datatable dt2=combobox.DataSource;

Its giving error how to i use like this..., error is given below

Cannot implicitly convert type 'object' to 'System.Data.DataTable'. An explicit conversion exists (are you missing a cast?)

Upvotes: 0

Views: 4066

Answers (1)

TGH
TGH

Reputation: 39278

System.Data.DataTable dt2=(System.Data.DataTable)combobox.DataSource;

You have to cast it since the DataSource property is of type object

Upvotes: 2

Related Questions