AddNewRecord XamDataGrid - infragistics

After entering a value in the AddNewRecord row, and clicking anywhere outside the row on the XamDataGrid seems to add the row to the collection.
How do I prevent mouse click from adding a new row to the collection.
Kindly any help

Clicking outside of the AddNewRecord ends edit mode on the record and if there were changes they are committed at that time which means the new record is added. If you were looking to only allow the record to be commmited when pressing the enter key and not by clicking another record in the grid, then you could use the following logic to set the mouse left button down as handled:
private bool editingAddNewRecord = false;
void XamDataGrid1_EditModeEnded(object sender, Infragistics.Windows.DataPresenter.Events.EditModeEndedEventArgs e)
{
this.editingAddNewRecord = false;
}
void XamDataGrid1_EditModeStarted(object sender, Infragistics.Windows.DataPresenter.Events.EditModeStartedEventArgs e)
{
this.editingAddNewRecord = e.Cell.Record.IsAddRecord;
}
void XamDataGrid1_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (editingAddNewRecord)
{
DataRecordPresenter drp = Infragistics.Windows.Utilities.GetAncestorFromType(e.OriginalSource as DependencyObject, typeof(DataRecordPresenter), true) as DataRecordPresenter;
if (!(drp != null && drp.IsAddRecord))
{
e.Handled = true;
}
}
}

Thanks for the answer #alhalama!
I noticed though that you don't handle the right mouse button down, and even when we do your solution doesn't work to support it. Also, with your solution I wasn't able to edit any other cells until I had hit Enter or Escape on the Add New Row record (which might be what some people want, but not me). Here is my modified solution that undoes changes to the Add New Record row's cell when the user clicks out of it, which also handles all mouse clicks (left, right, middle, etc.).
// Used to record when the user is editing a value in the Mass Edit row.
private DataRecord _addRecordCellBeingEdited = null;
private void XamDataGrid1_EditModeStarted(object sender, Infragistics.Windows.DataPresenter.Events.EditModeStartedEventArgs e)
{
if (e.Cell.Record.IsAddRecord)
_addRecordCellBeingEdited = e.Cell.Record;
}
private void XamDataGrid1_EditModeEnded(object sender, Infragistics.Windows.DataPresenter.Events.EditModeEndedEventArgs e)
{
_addRecordCellBeingEdited = null;
}
private void XamDataGrid1_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
if (_addRecordCellBeingEdited != null)
{
DataRecordPresenter drp = Infragistics.Windows.Utilities.GetAncestorFromType(e.OriginalSource as DependencyObject, typeof(DataRecordPresenter), true) as DataRecordPresenter;
if (!(drp != null && drp.IsAddRecord))
{
_addRecordCellBeingEdited.CancelUpdate();
}
}
}

Related

UWP - Platform::DisconnectedException while navigating between pages

I've got the following setup: A MainPage xaml-view and a SettingPage xaml-view. In the SettingPage xaml-view I activated the back button which is in the window title bar and I added a BackRequestedEventArgs. (Furthermore I have a DX12 xaml page but it is not involved to the navigation yet, so it will never get initialized.)
So my problem is: if I click on a flyoutitem called settings which is located in the MainPage, I'll get navigated to the SettingPage. The backbutton appears in the titlebar and if I click it, I get back to the MainPage. Now I do it once again: clicking on settings, navigating to SettingPage. Now if I click on the backbutton OR close the window the app crashes and shows me the following exception:
Platform::DisconnectedException ^ at 0x046BED80. HRESULT:0x80010108
My Question: How do I fix it?
Here is my Code for it:
MainPage Navigation:
void MainPage::MenuFlyoutItemSettings_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
this->Frame->Navigate(Windows::UI::Xaml::Interop::TypeName(SettingsPage::typeid));
}
SettingsPage:
// in Constructor
Windows::UI::Core::SystemNavigationManager::GetForCurrentView()->AppViewBackButtonVisibility = Windows::UI::Core::AppViewBackButtonVisibility::Visible;
Windows::UI::Core::SystemNavigationManager::GetForCurrentView()->
BackRequested += ref new Windows::Foundation::EventHandler<
Windows::UI::Core::BackRequestedEventArgs^>(
this, &SettingsPage::App_BackRequested);
void SettingsPage::App_BackRequested(
Platform::Object^ sender,
Windows::UI::Core::BackRequestedEventArgs^ e)
{
Windows::UI::Xaml::Controls::Frame^ rootFrame = dynamic_cast<Windows::UI::Xaml::Controls::Frame^>(Window::Current->Content);
if (rootFrame == nullptr)
return;
// Navigate back if possible, and if the event has not
// already been handled.
if (rootFrame->CanGoBack && e->Handled == false)
{
e->Handled = true;
rootFrame->GoBack();
}
}
Furthermore both methods have onSuspending and onResuming handlers added by me manually, but they are both empty:
//in constructor
Application::Current->Suspending += ref new SuspendingEventHandler(this, &SettingsPage::OnSuspending);
Application::Current->Resuming += ref new EventHandler<Object^>(this, &SettingsPage::OnResuming);
void SettingsPage::OnSuspending(Object^ sender, SuspendingEventArgs^ e) {
}
void SettingsPage::OnResuming(Object^ sender, Object^ e) {
}
NOTE: If I delete the whole backbutton-code, the app never crashes with this exception, so I think it is an error in this code.
EDIT 2017-09-04:
After working on Sunteen Wu - MSFT's Answer from below I realised that even If I delete all the backbutton-code I will get this exception as soon as I enter the SettingsPage the first time and close the app. So here is my current scenario where I am getting the described exception:
The only code I've got now for navigation:
MainPage (in a custom settingsbutton):
this->Frame->Navigate(Windows::UI::Xaml::Interop::TypeName(SettingsPage::typeid));
SettingsPage (in a custom backbutton):
this->Frame->Navigate(Windows::UI::Xaml::Interop::TypeName(MainPage::typeid));
So after the first time I navigate to the settingspage by pressing the settingsbutton I get the described exception only if I shutdown the app (same if clicking on red x or stopping debugger). The navigation works fine though, I can swap between the pages as long as I want and I won't get the exception while running the app.
FINAL ANSWER 2017-09-06:
Combining Sunteen Wu - MSFT's Answer with deleting the above mentioned
Application::Current->Suspending += ref new SuspendingEventHandler(this, &SettingsPage::OnSuspending);
Application::Current->Resuming += ref new EventHandler<Object^>(this, &SettingsPage::OnResuming);
handlers is the solution for me. Now there is no Disconnectedexception and the Back-Button-Logic is also working!
Platform::DisconnectedException ^ at 0x046BED80. HRESULT:0x80010108
Actually you are meeting the cycles issue. For what it the cycles issue and how to resolve please reference Weak references and breaking cycles (C++/CX). You met the cycles issue when you subscribe the BackRequested event handle. With the WeakReference you will find the issue:
WeakReference wr(this);
Windows::UI::Core::SystemNavigationManager::GetForCurrentView()->
BackRequested += ref new Windows::Foundation::EventHandler<
Windows::UI::Core::BackRequestedEventArgs^>([wr](
Object^ sender, Windows::UI::Core::BackRequestedEventArgs^ e)
{
SettingsPage^ c = wr.Resolve<SettingsPage>();
if (c != nullptr)
{
Windows::UI::Xaml::Controls::Frame^ rootFrame = dynamic_cast<Windows::UI::Xaml::Controls::Frame^>(Window::Current->Content);
if (rootFrame == nullptr)
return;
if (rootFrame->CanGoBack && e->Handled == false)
{
e->Handled = true;
rootFrame->GoBack();
}
}
else
{
throw ref new DisconnectedException();
}
});
From the article, when an event handler throws DisconnectedException, it causes the event to remove the handler from the subscriber list. So that to resolve it, you can remove the event handle from subscriber list after back requested. The following code snippet showed how to remove.
Windows::Foundation::EventRegistrationToken cookie;
SettingsPage::SettingsPage()
{
InitializeComponent();
...
cookie = Windows::UI::Core::SystemNavigationManager::GetForCurrentView()->
BackRequested += ref new Windows::Foundation::EventHandler<
Windows::UI::Core::BackRequestedEventArgs^>(
this, &SettingsPage::App_BackRequested);
}
void SettingsPage::App_BackRequested(
Platform::Object^ sender,
Windows::UI::Core::BackRequestedEventArgs^ e)
{
...
Windows::UI::Core::SystemNavigationManager::GetForCurrentView()->
BackRequested -= cookie;
}
Additionally, I recommend you subscribe this event inside App.xaml.cpp to avoid this issue. You can subscribe it inside OnLaunched like follows:
void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e)
{
auto rootFrame = dynamic_cast<Frame^>(Window::Current->Content);
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == nullptr)
{
...
}
else
{
...
}
Windows::UI::Core::SystemNavigationManager::GetForCurrentView()->
BackRequested += ref new Windows::Foundation::EventHandler<
Windows::UI::Core::BackRequestedEventArgs^>(
this, &App::App_BackRequested);
}
void App::App_BackRequested(
Platform::Object^ sender,
Windows::UI::Core::BackRequestedEventArgs^ e)
{
...
}
More details you can reference BackButton official sample.

wicket I'm using three panels, but only one is displayed at a time, when the third panel is added to the code the second never appears

I have a Modal class, when this modal is opened, it shows a panel asking the user if the user wants to proceed with the operation. If the user selects Yes the request is sent to the DB, which takes some time, during this time the first panel should be replaced by the second (which displays a spinner). This indeed happens if we do not use the third panel. Although I want to replace the second panel by the third panel in order to inform the user if the operation was successful or not (which depends of the message object,if it is null or have an error message).
So when I use addNewPanel(panel3, target) I never see panel2. I put a thread.sleep(5000) instruction after addNewPanel(panel2, target) and even so, this panel didn't appeared, I only get the initial and panel3 in the end.
If I do not use panel3 I see panel2.
Does anyone have an idea why is this happening?
Below I have the code of the Modal class
public class DetailsModal2 extends Modal<IModel<UserDomain>>{
#SpringBean
private IService service;
private BootstrapAjaxLink<String> noButton;
private ResponseMessage message;
private ProcessingPanel panel2;
private AlertPanel panel3;
private Panel replacedPanel;
public DetailsModal2(String id, IModel<UserDomain> model){
super(id);
replacedPanel = new AreYouSure("replacedPanel");
replacedPanel.setOutputMarkupId(true);
add(replacedPanel);
panel2 = new ProcessingPanel("replacedPanel");
panel3 = new AlertPanel("replacedPanel");
addButton(new BootstrapAjaxLink<String>("button", null, Buttons.Type.Warning, new ResourceModel("details")){
private static final long serialVersionUID = 1L;
#Override
public void onClick(AjaxRequestTarget target) {
// TODO Auto-generated method stub
//I was expecting to see this panel
addNewPanel(panel2,target);
// this puts this button invisible
this.setVisible(false);
target.add(this);
//this changes the label of the No button to Close
noButton.setLabel(Model.of("Close"));
target.add(noButton);
if(!service.retrieveData())
{
message = service.addUser("X");
if(message == null){
panel3.updateClassAndText(true);
addNewPanel(panel3,target);
}
else {
panel3.updateClassAndText(false);
addNewPanel(panel3,target);
System.out.println(""+ message.getError());
}
}//close if
else if(service.retrieveData())
{
message = service.removeUser("X");
if(message == null){
panel3.updateClassAndText(true);
addNewPanel(panel3,target);
}
else{
panel3.updateClassAndText(false);
addNewPanel(panel3,target);
System.out.println(""+ message.getError());
}
}
else{
System.out.println("It was not possible to access the db");
}
}
}
});
noButton = new BootstrapAjaxLink<String>("button", null, Buttons.Type.Primary){
private static final long serialVersionUID = 1L;
#Override
public void onClick(AjaxRequestTarget target) {
close(target);
}
}.setLabel(Model.of("No"));
addButton(noButton);
}
public void addNewPanel(Panel addpanel, AjaxRequestTarget target ){
Panel newPanel = null;
newPanel = addpanel;
newPanel.setOutputMarkupId(true);
replacedPanel.replaceWith(newPanel);
target.add(newPanel);
}
}//close class
HTML
<wicket:extend>
<div><span wicket:id="replacedPanel"> </span></div>
</wicket:extend>
Wicket atmosphere is deprecated from wicket 8 and will not be supported anymore, so do not use it ..

Condition fulfilled but if-statement won't trigger?

I have a scene, and this fully functional button called btnRemove,
Button btnRemove = new Button("Remove");
btnRemove.setMinWidth(85);
btnRemove.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent t) {
if(mediaTable.getSelectionModel().isEmpty()){
txtNotification.setText("Please select an item from the list");
}
else{
medium.remove(mediaTable.getSelectionModel().getSelectedItem());
}
}
});
and now I want to make it so that when the DELETE-key is pressed, the btnRemove button is triggered and removes the item in focus/the selected element.
Here's the code:
scene.setOnKeyReleased(new EventHandler<KeyEvent>() {
#Override
public void handle(KeyEvent event) {
System.out.println(event.getCode());
if("DELETE".equals(event.getCode())) {
System.out.println("ATTEMPT ----");
btnRemove.fire();
}
}
});
When I run it, the console outputs DELETE whenever I press DELETE, but it doesn't output "ATTEMPT ----" after that.
I don't see any reason why it shouldn't trigger
What gives??
You are trying to compare a KeyCode to a String. Change the condition to -
if (KeyCode.DELETE == event.getCode()) { ... }
What you are seeing in the first println is the KeyCode's toString, which apparently returns it's name.

Adding Row Specific context menu to an UltraWinGrid

I'm a newbie using Infragistics. I'm trying to add context menu to a specific row/column in UltraWinGrid, which I'm not able to. Looks like adding context menu to the grid is simple but adding it to a specific row/column is not straight forward. Can you please tell me how to do this?
You could add a context menu to the form or control your grid will reside in and only display it in when they right click in the grid over the rows/cells that need that menu.
Here's an example, though it's not pretty.
private void UltraGrid_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
ContextMenu.Hide();
Point point = new System.Drawing.Point(e.X, e.Y);
UIElement uiElement = ((UltraGridBase) sender).DisplayLayout.UIElement.ElementFromPoint(point);
UltraGridCell cell = (UltraGridCell) uiElement.GetContext(typeof (UltraGridCell));
if (cell != null && UseThisContextMenu(cell))
{
ContextMenu.Show();
}
}
}
MouseDown does not work. Please use MouseUp.
private void UltraGrid1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
Point point = new System.Drawing.Point(e.X, e.Y);
UIElement uiElement = ((UltraGridBase)sender).DisplayLayout.UIElement.ElementFromPoint(point);
UltraGridCell cell = (UltraGridCell)uiElement.GetContext(typeof(UltraGridCell));
if (cell.Band.Index == 0)
{
if (cell.Column.Key.Equals("ColumnToShow"))
{
contextMenuStrip.Show();
}
else
{
contextMenuStrip.Hide();
}
}
}
}
}

How do I make pressing the Enter key cause focus to move to the cell below like Excel's default behavior?

I am using an Infragistics UltraWinGrid v9.1.
I want to allow the user to enter numerical data in a cell, press Enter and then have the focus on the cell below, like you see in Excel. It appears that the KeyUp event might be better than the KeyPressed event for this, but I keep throwing an exception that I have gone beyond the bounds of the UltraWinGrid even though I start at the top of a full grid. Here is the code I've tried:
private void ugrid_KeyUp(object sender, KeyEventArgs e)
{
UltraGrid grid = (UltraGrid)sender;
if (e.KeyCode == Keys.Enter)
{
// Go down one row
UltraGridCell cell = grid.ActiveCell;
int currentRow = grid.ActiveRow.Index;
int col = cell.Column.Index;
grid.Rows[currentRow + 1].Cells[grid.ActiveCell].Activate();
}
}
I expected this to make the cell in the same column but one row below to become the active cell with the call,
grid.Rows[currentRow + 1].Cells[grid.ActiveCell].Activate();
Instead an exception is thrown:
An exception of type
'System.IndexOutOfRangeException'
occurred in
Infragistics2.Shared.v9.1.dll but was
not handled in user code Additional
information: Index was outside the
bounds of the array.
Since I'm on row 0 and there exists a row 1 this is a surprise to me. The values for currentRow and col are 0 and 28 respectively. What would be a better approach?
btw I can do this again the cell below, where the values are currentRow = 1 and col = 28. The same exception is thrown.
Someone answered my question on the Infragistics fora...
private void ugrid_KeyUp(object sender, KeyEventArgs e)
{
var grid = (UltraGrid)sender;
if (e.KeyCode == Keys.Enter)
{
// Go down one row
grid.PerformAction(UltraGridAction.BelowCell);
}
}
I don't know if what I'm saying is valid also for the v9.1 but you can also do something like this:
yourGrid.KeyActionMappings.Add(new GridKeyActionMapping(Keys.Enter, UltraGridAction.BelowCell, 0, UltraGridState.Row, SpecialKeys.All, 0));
private void ulGrvProducts_KeyUp(object sender, KeyEventArgs e)
{
UltraGrid grid = (UltraGrid)sender;
if (e.KeyCode == Keys.Enter)
{
//Go down one row
grid.PerformAction(UltraGridAction.BelowCell);
}
}
After using grid.PerformAction(UltraGridAction.BelowCell) , active row will change but next cell is not be in edit mode.