Categories
.NET C#.NET VB.NET/VB WPF

WPF ComboBox: DataBinding with DataTable

Well it seems easy thing, but it took a while for me to get it working. Frankly I still don’t know why it works this way, but at least it works. With WPF I was expecting something as easy as giving DataTable object to ComboBox by it’s property and define the Data Field and Value field as in ASP.NET dropdownlist and it will bind, but this was not the case or at least the syntax is little different. So it goes like

ComboBox cb = new ComboBox(); /// You might already have object of it, so I just create it for sake of understanding here.
cb.ItemSource = MyDataTable.Rows; /// Yup, DataTable will not bind but it's rows collection will.
cb.DisplayMemberPath = ".[" + YourColumnNameVariable + "]"; ///in other other ".[columnname]" is what is expected;
cb.SelectedValuePath = ".[" + YourColumnNameVariable2 + "]"; ///in other other ".[columnname]" is what is expected;

This is all we need to do to get it working.

Categories
.NET ASP.NET Blog: My thoughts C#.NET Joyous

Working Lot of new methodology

It is good to back as programmer. Loving my new phase of development career, I got involved in development of a online card game. After lot of thinking and reading, I decide to use some new technology and methodology which I have been hearing about a lot. I don’t dare to use them as I feel the kind of project we were doing lately are not big enough to learn and implement those concepts. After for this project it really become necessity to these technology rather than just a decision making. For example to build a game UI, I have three option GDI+, DirectX or WPF.. I have done GDI+ before and doesn’t feel it is best to make complex Graphical interface even for like of poker game. Though I use it to build Chess Interface, but I know how problematic it was. Second came in DirectX, the best but the complex solution. I need more time to learn it and project is getting delayed. Then I choose to learn and work on WPF which is relatively easier than DirectX.

It was really a nice decision to choose WPF. It is not only easier for me to learn as I already have some experience in HTML and web programming, but it give me control which is best suited for programmer of my culture. With no efforts I am now able to create a better looking UI. Ofcourse I didn’t test the UI on Windowx XP yet, but otherwise it looks great. I am not going to test it on Windows XP anyways as we don’t going to support it. Once I have the UI ready. I need to now communicate with Online database. So for this I already know the solution called as Web Services. But where will I found the Web Service in Visual Studio 2010 .. oh I think they rename it as WCF.. nope, they make a new concept altogether called WCF. Hmm.. with past experience of webservice I know that it was the perfect solution for me, but again WCF is almost similar no difference to code, so what harm it does to use it. Afterall it bring some new security measure and ease. So I again learn WCF and it took me 1 hr to cover the difference between Web Service and WCF and I am up and ready with my solution.

Making game UI is really so exciting that I am now looking for opportunity to upgrade my Chess game to WPF interface. Programming is really fun with those concept of programming and tools that I learn in recent past. It was complex then before in planning, but easy to implement. However the attitude of programmer is they need something ease to plan and implementation they are not bothered. I must suggest using WPF and WCF in your project where you need them. I haven’t try but they says WPF and Silverlight has same code or reusable. Well if that is the case then surely I will start giving Silverlight solution in next quarter or so.