473,473 Members | 2,169 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

using System.Reflection to invoke private method ColumnHeaderClick

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("C olumnHeaderClicked",
System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.NonPublic);
mi.Invoke(dg, new object[] {pd});
}
Nov 17 '05 #1
1 6606
I've discovered that it actually does sort in ascending order, but then
another sort immediately follows to make it look like it's only sorts by
descending. The ascending table could be seen when I inserted a messagebox
in the dgMouse (MouseUp) event. Before ok is pressed, the table ascends.
Then after ok is pressed, it goes to descending. The only change made was
adding the MessageBox. The public void SortColumn(int columnIndex) remains
the same (way below).
Thanks again for any help,
Mel

private void dgMouse(object sender, MouseEventArgs e)
{
DataGrid.HitTestInfo HitInfo = dg.HitTest(e.X, e.Y);
if (HitInfo.Row < tCat.Rows.Count && HitInfo.Row > -1)
{
if(HitInfo.Type != DataGrid.HitTestType.ColumnHeader)
{
this.dg.Select(HitInfo.Row);
row = HitInfo.Row;
xFile = int.Parse((tCat.Rows[row]["File"]).ToString());
}
}
if(HitInfo.Type == DataGrid.HitTestType.ColumnHeader)
{
columnIndex = HitInfo.Column;
this.SortColumn(columnIndex);
MessageBox.Show(xFile.ToString());
}

"melanieab" wrote:
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("C olumnHeaderClicked",
System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.NonPublic);
mi.Invoke(dg, new object[] {pd});
}

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: samlee | last post by:
Hi All, I'm learning how to write C# using reflection, but don't know how to code using reflection this.Controls.Add(this.label1); Could anyone help, Thank in advance. ...
4
by: Brian Brane | last post by:
I have properties that wrap DataRow columns as in: public int aNumber { get{ return m_DataRow; } set{ m_DataRow = value; } } If the column happens to contain DBNull, I get a cast exception...
7
by: Clint Herron | last post by:
Howdy! I posted this question on CSharpCorner.com, but then realized I should probably post it on a more active newsgroup. This will be my only cross-post. I'm creating a game engine, and...
0
by: melanieab | last post by:
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...
3
by: Olivier BESSON | last post by:
Hello, I have a web service of my own on a server (vb.net). I must declare it with SoapRpcMethod to be used with JAVA. This is a simple exemple method of my vb source : ...
5
by: Anders Borum | last post by:
Hello! Whilst refactoring an application, I was looking at optimizing a ModelFactory with generics. Unfortunately, the business objects created by the ModelFactory doesn't provide public...
3
by: Me | last post by:
I am trying to figure out any issues with calling System.Reflection.MethodInfo.Invoke() when dealing with multiple threads. For instance.. Say I have a class that allows you to pass in a...
2
by: diego | last post by:
hi everyone, i have a sub that opens a form given the form's name as string and opens it using System.Reflection. How can I set the form's properties at runtime. Here is my code. Public Sub...
3
by: binder.christian | last post by:
Hi! I have two applications: * mainapp.exe * plugin01.exe I have 2 "friend" variables in mainapp.exe: Friend gblConn as SqlConnection Friend gblPath as string
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.