![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
| | #6 (permalink) |
| | 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 Specs![]() |
| | #7 (permalink) |
| | 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 Specs![]() |
| 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 | |||