Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - How to specify an event handler for the GridViewColumnHeader control in C#?

 
 
Old 11-06-2006   #1 (permalink)
wackyphill@yahoo.com


 
 

How to specify an event handler for the GridViewColumnHeader control in C#?

I know its this for XAML:
<ListView GridViewColumnHeader.Click="MyHandlerFunc"/>

But how do you specify an event handler for the GridViewColumnHeader
control in C#?


My System SpecsSystem Spec
Old 11-06-2006   #2 (permalink)
Robin Davies


 
 

RE: How to specify an event handler for the GridViewColumnHeader contr

this.AddHandler(
GridViewColumnHeader.ClickEvent,
new RoutedEventHandler(MyHandlerFunc)
);


"wackyphill@yahoo.com" wrote:

> I know its this for XAML:
> <ListView GridViewColumnHeader.Click="MyHandlerFunc"/>
>
> But how do you specify an event handler for the GridViewColumnHeader
> control in C#?
>
>

My System SpecsSystem Spec
Old 11-07-2006   #3 (permalink)
Bob


 
 

RE: How to specify an event handler for the GridViewColumnHeader contr

In article <FF7A9030-14F8-49C5-BFC7-E16D34993EC9@microsoft.com>,
RobinDavies@discussions.microsoft.com says...
> this.AddHandler(
> GridViewColumnHeader.ClickEvent,
> new RoutedEventHandler(MyHandlerFunc)
> );
>
>
> "wackyphill@yahoo.com" wrote:
>
> > I know its this for XAML:
> > <ListView GridViewColumnHeader.Click="MyHandlerFunc"/>
> >
> > But how do you specify an event handler for the GridViewColumnHeader
> > control in C#?
> >
> >

>


I messed with this for a while and saw that it was already answered by
Robin. But, I don't see GridViewColumnHeader as a member of ListView or
GridView... I originally instantiated a new instance of
GridViewColumnHeader in my code (below) but noticed the code works
without that line. Where's GridViewColumnHeader from?

-- sorry for wordwrap---

using System;
using System.Windows;
using System.Windows.Controls;

namespace Test.GridViewColumnHeaderTest
{
class GridViewColumnHeaderTest : Window
{
[STAThread]
public static void Main()
{
Application app = new Application();
app.Run(new GridViewColumnHeaderTest());
}
public GridViewColumnHeaderTest()
{
Title = "test";
Width = 300;
Height = 300;
ListView lv = new ListView();
GridView gv = new GridView();
lv.View = gv;
GridViewColumn col1 = new GridViewColumn();
GridViewColumn col2 = new GridViewColumn();
col1.Width = col2.Width = 150;
col1.Header = "col1";
col2.Header = "col2";
gv.Columns.Add(col1);
gv.Columns.Add(col2);
Content = lv;
//GridViewColumnHeader h = new GridViewColumnHeader();
AddHandler(GridViewColumnHeader.ClickEvent, new
RoutedEventHandler(GridViewColumnHeader_Click));
}

void GridViewColumnHeader_Click(object sender, RoutedEventArgs
e)
{
string strMessage = string.Format("sender type= {0}
\nSource= {1} \nOriginalSource= {2} \nRoutedEvent Name= {3}
\nRoutedEvent Name= {4}",
sender.GetType(), e.OriginalSource,
e.Source, e.RoutedEvent.Name, e.RoutedEvent.RoutingStrategy);
MessageBox.Show(strMessage);
}
}
}
My System SpecsSystem Spec
Old 11-07-2006   #4 (permalink)
wackyphill@yahoo.com


 
 

Re: How to specify an event handler for the GridViewColumnHeader contr

Indeed, it is kind of a mystery to me.
Thanks for the info Bob.

My System SpecsSystem Spec
Old 11-07-2006   #5 (permalink)
wackyphill@yahoo.com


 
 

Re: How to specify an event handler for the GridViewColumnHeader contr

What concerns me most about it is I am unsure how to determine which
listview control is actually being clicked as the original source is
not the ListView.

My System SpecsSystem Spec
Old 11-07-2006   #6 (permalink)
Bob


 
 

Re: How to specify an event handler for the GridViewColumnHeader contr

In article <1162910700.953911.243530@i42g2000cwa.googlegroups.com>,
wackyphill@yahoo.com says...
> What concerns me most about it is I am unsure how to determine which
> listview control is actually being clicked as the original source is
> not the ListView.
>
>


It is a ListView (the Source, not OriginalSource). I had a small error
in the string.format... try this handler...

void GridViewColumnHeader_Click(object sender, RoutedEventArgs
e)
{
string strMessage = string.Format("sender type= {0}
\nSource= {1} \nOriginalSource= {2} \nName= {3} \nRoutedEvent
RoutingStrategy= {4}",
sender.GetType(), e.Source,
e.OriginalSource, e.RoutedEvent.Name, e.RoutedEvent.RoutingStrategy);
if (e.Source is ListView)
{
ListView l = e.Source as ListView;
string s = l.Name;
}
MessageBox.Show(strMessage);
}
My System SpecsSystem Spec
Old 11-07-2006   #7 (permalink)
wackyphill@yahoo.com


 
 

Re: How to specify an event handler for the GridViewColumnHeader contr

Yup, you're right again Bob!

Hey, Thanks for the help I really appreciate it. You've been a big help.

My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Add Event Handler to dynamic DropDownList?????? .NET General
DataGridView.DragDrop Event Handler Causes a DataError? (May be a Bug?!?!?!) .NET General
Questions about delegate and event handler .NET General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46