DevExpress DXGrid column header double click event - c#

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.

Related

UWP CustomRenderer for Checkbox: Pointer over Checkbox changes style?

I'm working with Xamarin.Forms and I made a CustomRenderer for Checkbox in UWP. When I set all the Checkboxes of my items in the ListView to true by clicking the button "Alle", the Checkboxes are displayed correctly with the check inside the box:
However, if I hover my mouse over the Checkboxes, they immediately change their appearence (the check disappears but it's still selected). In the following screenshot, I moved my cursor over the 3rd - 7th Checkboxes:
This is my overridden OnElementChanged method in the CustomRenderer:
protected override void OnElementChanged(ElementChangedEventArgs<EvaCheckbox> e)
{
base.OnElementChanged(e);
var model = e.NewElement;
if (model == null)
{
return;
}
nativeCheckbox = new CheckBox();
CheckboxPropertyChanged(model, null);
model.PropertyChanged += OnElementPropertyChanged;
nativeCheckbox.Checked += (object sender, Windows.UI.Xaml.RoutedEventArgs eargs) =>
{
model.IsChecked = (bool)nativeCheckbox.IsChecked;
};
nativeCheckbox.Unchecked += (object sender, Windows.UI.Xaml.RoutedEventArgs eargs) =>
{
model.IsChecked = (bool)nativeCheckbox.IsChecked;
};
SetNativeControl(nativeCheckbox);
}
I tried to override the PointerEntered event of nativeCheckbox. It works, for example if I set the model.IsChecked to true on this event, it will be set to true:
nativeCheckbox.PointerEntered += (s, args) =>
{
model.IsChecked = true;
};
But I don't know how to (if even at this place) prevent the checkbox from changing it's appearance when moving the cursor above the Checkbox. Just leaving the triggered event with empty code like this won't change anything about the described behaviour:
nativeCheckbox.PointerEntered += (s, args) => { };
How can I prevent the Checkbox from changing it's appearance when I move my cursor over it?
Update:
I've created a sample project for this issue. You can find the repository here: https://github.com/Zure1/CustomCheckbox
It has the exact same described behavior. In the following screenshot I pressed the button "All" on the bottom of the screen and then the checkboxes look like correct with a check inside of them:
After moving the mouse cursor over the bottom 3 checkboxes, their change their appearance:
Information: I'm debugging on my desktop (Windows 10). I don't know if this issue exists on WinPhone. Just in case you're wondering why my checkboxes are red: My system color in Windows is red.
This is a tricky one as I have been struggling with this issue for a while, I'll try my best to answer this.
TL;DR: It's caused by ViewCell.
The issue comes down to Xamarin Forms ListView and ViewCell.
I haven't been able to track down the cause yet for many months and the way I get around this issue is by refreshing the ListView every time a change happens forcing a redraw of the entire ListView which can really impact performance.
My educated guess on what the cause could be is the rendering code for the ViewCell is missing something.
As for your particular issue, I have created a CheckBoxCell which you can use to display a list of checkboxes with a title. I forked your project and made the changes.
This will display something similar to what you are trying to achieve and doesn't have rendering issues so will be a good starting point. You are able to customize this to display images and the like but you'll have to do that in the platform-specific layout code.
Please note that I have only created the code for UWP and that should be enough to get you going for the other platforms.
I hope this helps somewhat.

How do I alter the value being updated in a ListView?

I can't seem to find an answer to this, maybe I'm not using the correct terminology.
I have a ListView that is editable, I want it so that if a user clicks on Edit and then Update, that the field is updated with the value from another textbox, not the field they are editing.
The reason for this is that I have a Colour Picker that alters the value of a textbox, when they click Update I want this value to be the updated value.
I guess I utilise the ItemUpdating event, but I don't have much in the way of code because I'm pretty lost. I have this so far:
protected void ListView2ItemUpdating(object sender, ListViewUpdateEventArgs e)
{
var selectedItem = ListView2.Items[ListView2.EditIndex];
// I have no idea what to put here
something = ColourChosen.Value;
}
Here is an image that I hope will make what I'm trying to do a little more understandable:
If any one could point me in the right direction of any examples, that would be much appreciated.
Although this doesn't answer my initial question this does what I want to happen.
What I should be doing is altering the database that ListView is attached to.
I use this code:
protected void ListView2ItemUpdating(object sender, ListViewUpdateEventArgs e)
{
using (var myEntities = new i96X_utilEntities())
{
var myPlotColour = (from plotC in myEntities.PlotColours
where plotC.ID == selectedID
select plotC).Single();
myPlotColour.PlotColour1 = ColourChosen.Value;
myEntities.SaveChanges();
}
}
So, even though I have no idea how to intercept a field being updated in a ListView, in this example I don't need to.

ASP Listview - checkbox event findcontrol

I'm trying to build a Listview EDIT/Insert template where I can use a checkbox to enable updating multiple database tables but to little success.. I managed to get the insert working by performing some foul sorcery on the Listview inserting event. But I'd prefer that it works with the Checkbox OnCheckedChanged event as it feels abit more kosher in my mind, and of course the added benefit on it working for the edittemplate..
protected void checktest_clicked(object sender, EventArgs e)
{
//testlabel.Text = testcheck.Checked.ToString(); <-- exists outside of LW
// so it works
//Label hejha = (Label)lwRapport.FindControl("testlabel");
CheckBox trial = (CheckBox)lwRapport.FindControl("upParameter");
if(trial != null)
{
if(trial.Checked == true)
{ testlabel.Text = "finally"; }
if(trial.Checked == false)
{ testlabel.Text = "Nope, not going to happen"; }
}
if (trial == null)
{ testlabel.Text = "not wanted"; }
}
That's my test snippet for checking how the FindControl works and so far I've been quite unsuccessful making it do what I want it to do..
Any Correction on faults / hack / workaround for this matter would be apritiated
EDIT1*
The checkbox is inside of the listview, more precisely in the inserttemplate. The template looks something on the lines like this:
textbox <bind"table1.element">
textbox2 <bind"table1.element2">
checkbox [_]
textbox3 <bind"table2.element">
Observe that the snippet above is just a pseudocode snippet of my layout not the acctual layout. What I'm attempting is to find the checkbox and bind it's checked value to a parameter which passes a couple of checks in the SPROC then executes the UPDATE command
You seem to be not able to find the check box control from the list view. This is because you are searching for the check box inside the list view, and what you should be doing is searching for it inside the selected item.
You can have a look at this. Although it's GridView, I think it will works too.

Get cell contents of a selected row in a DataGridView

I have a DataGridView populated from a database.
I am trying to get the contents of the row that is selected on the RowEnter event. I have set the grid's selection mode to FullRowSelect
I have tried the following:
int orderId = (int)dgUnprocessedCards.Rows[dgUnprocessedCards.SelectedCells[0].RowIndex].Cells[0].Value;
this keep throwing the error
Index was out of range. Must be non-negative and less than the size of the collection.
Any help is appreciated.
I've just tried this in a sample datagridview app and it works just fine so there must be something going on which you haven't told us about.
First thing to do is break your one big statement up into discrete smaller statements so you can see exactly where the failure is.
You can rewrite the code above to something like this for debugging purposes:
var cellindex = dgUnprocessedCards.SelectedCells[0].RowIndex;
var cellcollection = dgUnprocessedCards.Rows[cellindex].Cells[0];
int orderId = (int)dgUnprocessedCards.Value;
Also, you should be able to do the following to achieve what you want:
int orderId = (int)dataGridView1.SelectedRows[0].Cells[0].Value;
That uses the SelectedRows collection which is a little bit more concise and I'd say the more usual way of accessing selected items from the datagridview.
Finally, you probably want to do checking around your cast of the value, since the Value might not necessarily be an int. Something like:
int orderid;
if (!int.TryParse(cellcollection.Value.ToString(), out orderid))
{
// Some logic to deal with the fact that Value was not an int
}
When is the SelectionChanged event raised?
Now - as you mention, your selection changed event fires while loading data into the grid. This doesn't seem to cause a problem in my test version but could be part of your issue.
Why this happens should not be related to the type of data source you are using, but to when you attach the selection changed eventhandler. This is because databinding causes a selection changed event to be raised.
If you add an eventhandler for the DataBindingComplete event and attach your SelectionChanged or RowEnter eventhandlers there, you should not see the handler invoked during databinding.
void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
this.dataGridView1.RowEnter += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_RowEnter);
this.dataGridView1.SelectionChanged += new System.EventHandler(this.dataGridView1_SelectionChanged);
}
Note that you will need to delete the designer generated event attachment and reference the designer generated methods for this to work.
This also works:
int orderId = (int)dgUnprocessedCards.SelectedCells[0].OwningRow.Cells[0].Value;
You can get specific column value when you click on Datagridview column
private void DataGridview_CellContentClick(object sender,
DataGridViewCellEventArgs e) { int col = e.ColumnIndex; int row =
e.RowIndex; Var value=DataGridview.Rows[row].Cells[col].Value; }
What I tried to do worked fine but the binding was calling the selection changed event. So I done what David Hall suggested (attaching and detaching the event) and I also put it in a try catch block and now it works perfectly.

Where to find TreeListViews ColumnHeaderClick Event?

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.

Categories