Sunday, June 8, 2008
Saturday, December 8, 2007
(Assume there is a class called opportunity that has a property called Properties, which returns a value type based on a column name and that there exist methods to give what column the user clicked on and what order did he want)
int ascending = GetOrder(); // This method will return 1 if ascending and -1 if
string columnName = GetSortedColumn(); // Get the name of the column to be sorted
// One-liner sort
opportunities.Sort((a, b) => ascending * ((IComparable)a.Properties [columnName] ).CompareTo(b.Properties[columnName]));
Isnt this real simple? Now, the additional benefit that we get out of this is the ability to pass in local variables (ascending and columnName in this case) into the lambda expression and thereby the comparison, which would have never been possible if I used the "implementing IComparable or IComparer" route.
Thursday, July 5, 2007
Recently I embarked into the exercise of hosting some ActiveX controls inside of a windows form. Found out that AxImp.exe was the way to go. Its a neat tool using which you can create a wrapper for the ActiveX control as a dll or as a C# file. After you create the wrapper for the ActiveX control as a C# file (emitted as a Winform user control that derives from AxHost), you can add attributes on the control to make it appear in toolbox. I tried this to host the Outlook List View control in a winform. Works like a charm :) More details on the usage of the tool can be found here.
Saturday, April 28, 2007
private void WriteChanges(DataTable dataTable )
aeAdapter.RowUpdating += new SqlCeRowUpdatingEventHandler(adapter_RowUpdating);
void adapter_RowUpdating(object sender, SqlCeRowUpdatingEventArgs e)
e.Command.Parameters["@Updated"].Value = FormatDate(e.Row["Updated"]);
private string FormatDate(object datetime)
if (datetime == null Convert.IsDBNull(datetime)) return "";
DateTime value = Convert.ToDateTime(datetime);
return value.ToString (System.Globalization.DateTimeFormatInfo.InvariantInfo) + "." + value.Millisecond.ToString();
Sunday, April 1, 2007
Saturday, March 10, 2007
I have seen this work. Worth a try.