Where to find TreeListViews ColumnHeaderClick Event? - c#

I'm developing a tool which shows data from a database in a hierarchical manner. As there are additional data for each item I'm using a TreeListView control to display them in additional columns. The number of columns is determined by user input.
The custom control that I'm using is Ricciolos TreeListView:
http://windowsclient.net/blogs/ricciolocristian/archive/2008/03/22/a-complete-wpf-treelistview-control.aspx
My problem now is, that I need to catch the ColumnHeaderClick event to apply a sorting logic. I already interviewed auntie Google, but no results.
Maybe somene here knows where to find such an event and how to determine which column header has been clicked.
Thanks

You would need to add a handler for the GridViewColumnHeader.Click event. This post describes how to do it for the ListView, which uses the same underlying controls. This code was adapted from that link:
myTreeListView.AddHandler(GridViewColumnHeader.ClickEvent, new RoutedEventHandler(this.OnGridViewColumnHeaderClicked));
private void OnGridViewColumnHeaderClicked(object sender, RoutedEventArgs e) {
MessageBox.Show("testing");
}
Alternatively, you can attach a handler via XAML like so:
<my:TreeListView GridViewColumnHeader.Click="OnGridViewColumnHeaderClicked" />
The e.OriginalSource will include the GridViewColumnHeader, and e.Source/sender would be the TreeListView.

Related

Handle all elements Holding event

I have an idea of implementing holding event handler for all text-type controls ( label, textbox, passwordbox, hyperlink etc. ) in order to show message popup for allowing suggest a better translation of this text.
Is it possible to implement such type of event handler for all controls that get added/removed from/to visual tree.
Without doing such for each element:
<TextBox Holding="HoldingEventHandler"/>
I have tried this in my MainPage.xaml.cs:
AddHandler(Control.HoldingEvent, new RoutedEventHandler(HoldingOccured), true);
But it fails with exception:
Value does not fall within the expected range.
If you implement Holding in xaml and ask for new handler the system will generate the follow callback.
private void WindowsPage_Holding(object sender, HoldingRoutedEventArgs e)
{
}
So, thiis is a correct call parameters.
AddHandler(Control.HoldingEvent, new HoldingEventHandler(HoldingOccured), true);

How to find the id of dragged control

I am implementing drag and drop functionality among lables. I want to find the ID of a dragged control like label, button, etc so that I can assign a text to it.
I am not sure how to get that data through the events. Any suggestion will help.
you can use Drag_Enter and DragOVer Events, to achieve the goal DragEnter Doucmentation
and DragOver Documentation
alternativily you can check following tutorials
Code project : Drag and Drop in Windows Forms
Code Project : Drag and Drop UI in WinForms
check out System.Windows.Forms.DragEventArgs e
void MyControl_DragDrop(object sender, DragEventArgs e)
{
var controlBeingDrag = (Label)sender; // cast from object
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop, false);
}
the control sending drag event is object sender
Assuming you've done your research to figure out how to do drag and drop of controls on your form (and your question is really only limited to your question title: How to find the id of dragged control) most standard WinForm events provide a parameter (object sender) which represents the control used to invoke the event. You should be able to get its ID as you would normally.
Apparently it is less obvious how to consistently get the ID from a WinForm control. Luckily, Brian McMaster has a (fairly old meaning only possibly relevant) MSDN blog post for doing just that. In .NET 3.5 I'd probably use this old post as the start to an extension method for control objects.
If your question is broader than that then you may benefit from #Ravi's links, but on SO we generally expect that you do your own research. Please be sure to do so before asking questions.

Undo Context Menu on UltraWinGrid

I am trying to put up an Undo context Menu on UltraWinGrid to undo the last change that was made to the grid
The code looks like this
private void _undoAll_Click(object sender, EventArgs e)
{
this.GridName.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.Undo);
}
But its not providing the desired result. I can not use DataTable UndoChanges feature because I am binding a custom class to this Grid
Make sure you set DisplayLayout.Override.AllowMultiCellOperation to include the flag that allows the Undo operation.
In code you should set something like this in your Form_Load event:
this.GridName.DisplayLayout.Override.AllowMultiCodeOperations =
AllowMultiCellOperation.Undo | AllowMultiCellOperation.Redo;
also I have found this thread on Infragistics site that explain better what going on here

DevExpress DXGrid column header double click event

I have to check / uncheck all the checkboxes (toggle) in a column when the user double clicks the column header.
How can I implement this behaviour in the DevExpress DxGrid control?
I have searched the DevExpress support forum but I haven't found a solution.
Also, i am working on MVVM Pattern.
This case works for WinForms, not tested in WPF yet, I posted might it direct you to some lights:
There is a workaround to accomplish this behave, you have to implement yourGrid_DoubleClick Event Handler, then calculate the hit Info of the mouse click, the hit info object will tell you if the double click was on a column, something like:
private void yourGridViewName_DoubleClick(object sender, EventArgs e)
{
DevExpress.XtraGrid.Views.Grid.GridView sndr =
sender as DevExpress.XtraGrid.Views.Grid.GridView;
DevExpress.Utils.DXMouseEventArgs dxMouseEventArgs =
e as DevExpress.Utils.DXMouseEventArgs;
DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hitInfo =
sndr.CalcHitInfo(dxMouseEventArgs.Location);
if (hitInfo.InColumn)
{
string x = hitInfo.Column.Name;
//Rest of your logic goes here after getting the column name,
//You might now loop over your grid's data and do your logic
}
}
but you have to notice that this action will not prevent the sorting that column's header do, you might need to disable sorting for this grid
Hope this helped.

CAB Framework WorkItem event switching between user controls

I have a problem using CAB Framework. I created some GUI User control interfaces and put them on my screen, that works fine. However, I would like to save my data between the different user controls. I made some DataContracts using WCF and I put the data I need in the DataContract and put those in properties so they're accessible from the WorkItem. Now I used the following function in the WorkItem to process the data:
protected override void OnWorkItemSmartPartChanged(object sender, EventArgs e)
{
MessageBox.Show(_testWorkItemControlAdres.AdresContract.Gemeente);
}
When I change between user controls, I want to see if it can succesfully access the data. However, when I switch between the wizard steps (the user controls) it never triggers the event. Do I need to add this event somewhere else or not?
Did you actually link the event to the WorkItem?
Workspace.SmartPartActivated += new EventHandler(OnWorkItemSmartPartChanged);
Cheers

Categories