在WPF中将数据绑定到Combobox [英] Bind data to Combobox in WPF
本文介绍了在WPF中将数据绑定到Combobox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将数据列表中的collectorDTO列表中的配置文件绑定到wpf中的Combobox,请找到下面的代码
I am trying to bind profile from the list of collectorDTO to Combobox in wpf from list of data, Please find the code below
List<CollectorDTO> cdlist = new List<CollectorDTO>();
cbProfile.ItemsSource = cdlist;
cbProfile.DisplayMemberPath = "Profile";
cbProfile.SelectedValuePath = "Profile";
收藏家DTO包含以下变量和get set方法
Collector DTO contains the following variables with get set method
private int _coldataId;
private string _profile;
private string _protocol;
private string _hosttype;
private string _host;
private string _uid;
private string _pwd;
private string _remdir;
private string _locdir;
private string _database;
private string _audittrail;
private string _skeleton;
private string _tmode;
private string _cmdstr;
private string _starttime;
private string _stoptime;
private int _period;
private string _addinfo;
推荐答案
Sandeep,
我收集的内容你将cdlist声明为一个新的instanciated变量,但你没有用任何数据填充它。相反,您将空列表绑定到组合框。您需要添加一个返回ColectorDTO对象列表的方法。类似的东西..
Sandeep,
From what I gather you are declaring cdlist as a newly instanciated variable, but you are not filling it in with any data. Instead you are binding an empty list to your combobox. You need to add a method that returns you a list of ColectorDTO objects. Something like..
cdlist = GetCollectors();
其中函数GetCollectors返回它从某些数据源检索到的CollectorDTO对象列表。
where the function GetCollectors returns a list of CollectorDTO objects it has retrieved from some source of data.
这篇关于在WPF中将数据绑定到Combobox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文