开发者

Unboxing ComboBox Items

开发者 https://www.devze.com 2022-12-23 00:41 出处:网络
since method Add() takes Obje开发者_JS百科ct as an argument, can I add for example datatables, then unbox them?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消