There are several ways to sort data in C# but one of the easiest ways is using BindingSource sort capability.
Depending on what object (underlying list) is linked to the BindingSource as its DataSource and whether it has implemented IBindingList or IBindingListView interfaces or not, you can use this feature.
To find out whether a BindingSource with current DataSource supports sorting, use ‘SupportsSorting’ property:
bindingSource1.Sort = "Code, Name";
Similarly, you can benefit from BindingSource.Filter .
If you want to capture changes in ComboBox you can use ‘SelectedIndexChanged’ or ‘SelectedValueChanged’ events. However, if you want to get changes only when the user changes the selection, use ‘SelectionChangeCommitted’ event instead.
SelectionChangeCommitted occurs only when the ComboBox selection changes by user (via keyboard or mouse) and it is not raised when the selection changes programmatically.
private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
if (comboBox1.SelectedIndex == 1)
The simplest way to replicate (repeat) a string in C# is using string class constructor:
string s = new string('#', 4); //result: ####
If you want to replicate a sub-string (not only a char), use this:
string.Concat(System.Collections.ArrayList.Repeat("#0",4).ToArray()); //result: #0#0#0#0
When you want to use a data bound ComboBox in .NET (C#, VB, etc), you should set a few properties such as DataSource, DisplayMember and ValueMember.
It works fine unless you want to set SelectedValue for the first time. It won’t be set!
I found that BindingContext property must be created before initializing SelectedValue:
ComboBox1.BindingContext = new BindingContext();
ComboBox1.DataSource = MyDataSet.DefaultView
ComboBox1.DisplayMember = "Title";
ComboBox1.ValueMember = "Code";
ComboBox1.SelectedValue = 1;
I studied most of the book and I was evaluated by a couple of .NET experts in the end. The interview was successful and I officially started developing database applications in C#.
I try to update here as soon as I learn new techniques, tips and tricks. For now, I start with ” LINQ to SQL”.
LINQ to SQL is a kind of sophisticated OR Mapper (Object Relational Mapper) which has several useful features that results easier and simpler development.
This is what Microsoft experts say:
“LINQ to SQL provides a runtime infrastructure for managing relational data as objects without losing the ability to query. Your application is free to manipulate the objects while LINQ to SQL stays in the background tracking your changes automatically.”
For more information please visit: http://msdn.microsoft.com/en-us/library/bb425822.aspx
A friend of mine who showed me the capabilities of LINQ to SQL, also said that this technology is obsolete right now and “Entity Framework” should probably be replaced with it. Entity Framework version 1 was released with .NET framework 3.5 service pack 1 and the next version will be released by .NET framework 4.
Long time no update…
I couldn’t start reading the book until last week.
It’s an interesting book and helps you to switch to C# in the shortest time possible.
For me, with software designing and programming background, many concepts are similar but of course there are a few new features such as Generics, Attributes, etc. that weren’t in Delphi.
I have been reading two chapters a day and I’m currently reading the 12th chapter.
After 7 years of professional software development in VB and Delphi, I have finally decided to switch to C# .Net. There are several reasons for this decision which I’m not going to explain them.
I’m trying to utilize my previous Delphi experience and learn new programming technics as much as I can.
This blog may be useful for beginners at first and gradually for professionals later when I got improved. Your feedback would be a good motivation for me to continue.
By the way, I’m going to start with “Pro C# 2008 and .NET 3.5 Platform” by Andrew Troelsen.