什么方法对美国州ListBox / DropDownList有利

时间:2011-12-28 22:02:35

标签: object binding listbox datatable states

在WPF中绑定US State的最佳方法是什么(在ListBox或DropDownList中)?我应该使用DataTable来绑定这些数据吗?是否将DataTable绑定到WPF对象编程方法?或者我应该使用class / object。我的意思是从数据库获取数据并将其转换为通用对象列表,然后将此列表绑定到WPF对象?

谢谢,

1 个答案:

答案 0 :(得分:0)

 public class States
    {
        private string name;  
        public string Name    
        {
            get
            {
                return name;
            }
        }

        private string id;  
        public string Id  
        {
            get
            {
                return id;
            }
        }
    }

        List<States> states = new List<States>();

        //get from database


        foreach( states DataSource)
        {
            name = "Alabama";
            id = "1";
        }

        // next Cache list of states for better performance

很多方式...... 一种方法是使用列表类。从数据源获取,下一个缓存以获得更好的性能。