G
Guest
Hi again,
I'm trying to programatically sort a datagrid. I did find the following
code, and it does work, but, when a column header is clicked, the data only
sorts in descending order. Clicking the same column header again doesn't
change anything, although clicking a different column header re-sorts the
data in descending order according to whatever's in that column. I'm pretty
much at a loss as to how to even start fixing this. Any suggestions?
Thanks,
Mel
public void SortColumn(int columnIndex)
{
System.ComponentModel.PropertyDescriptor pd =
dg.TableStyles[0].GridColumnStyles[columnIndex].PropertyDescriptor;
//now invoke ColumnHeaderClicked method using system.reflection tools
System.Reflection.MethodInfo mi =
typeof(System.Windows.Forms.DataGrid).GetMethod("ColumnHeaderClicked",
System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.NonPublic);
mi.Invoke(dg, new object[] {pd});
}
I'm trying to programatically sort a datagrid. I did find the following
code, and it does work, but, when a column header is clicked, the data only
sorts in descending order. Clicking the same column header again doesn't
change anything, although clicking a different column header re-sorts the
data in descending order according to whatever's in that column. I'm pretty
much at a loss as to how to even start fixing this. Any suggestions?
Thanks,
Mel
public void SortColumn(int columnIndex)
{
System.ComponentModel.PropertyDescriptor pd =
dg.TableStyles[0].GridColumnStyles[columnIndex].PropertyDescriptor;
//now invoke ColumnHeaderClicked method using system.reflection tools
System.Reflection.MethodInfo mi =
typeof(System.Windows.Forms.DataGrid).GetMethod("ColumnHeaderClicked",
System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.NonPublic);
mi.Invoke(dg, new object[] {pd});
}