Unboxing ComboBox Items
since method Add() takes Obje开发者_JS百科ct as an argument, can I add for example datatables, then unbox them?
example:
cmbEmpresa.Items.Add(dt1);
cmbEmpresa.Items.Add(dt2);
cmbEmpresa.Items.Add(dt3);
then do something like:
datagrid.datasource=(DataTable)cmbEmpresa.SelectedItem;
EDIT:
and what about adding different type of objects, how can I unbox them according to the SelectItem's original type?
Boxing and unboxing actually means changing a value type into an object and vice-versa, so that's probably not the right term for what you mean.
You can store any type of object you like in your ComboBox and cast back to the original type as needed.
精彩评论