PrintDialog.ShowDialog() not returning null - wpf

The ShowDialog method of the PrintDialog class in WPF is declared to return nullable bool (i.e. bool?), which is consistent with the documentation details:
"true if a user clicks Print; false if a user clicks Cancel;
or null if a user closes the dialog box without clicking Print or Cancel." from http://msdn.microsoft.com/en-us/library/system.windows.controls.printdialog.showdialog.aspx
However, in the code below, no matter how I close the dialog, (I tried the X and Alt-F4) I can never make it return null. Unless I press the Print button, it is always false. This is my test code:
PrintDialog pd = new PrintDialog();
bool? result;
result = pd.ShowDialog();
Do you get the same behaviour? Is the documentation wrong or am I misinterpreting it or not testing correctly? Perhaps this is OS related, I am running Windows 7 Enterprise.
Thank you.
L

Related

Concurrency Error WinForms Binding Source Navigator

I have a form with customer info that needs to be processed one transaction per page. I'm using the binding navigator to manage my pagination.
It works in all but some cases. In the cases where it doesn't work, I have to open a different window to look up information and return it to the main form. Here is the code for that:
// save current work
updateDataTable();
// Open a window and get new customer info
// CurrentCustomer is returned from the opened window
using (SqlConnection cx = new SqlConnection(GetConnectionString()))
{
DataRowView dataRow = (DataRowView)procBindingSource.Current;
dataRow.BeginEdit();
dataRow["CUSTOMER"] = CurrentCustomer;
dataRow.EndEdit();
updateDataItems();
SqlCommand cmd = new SqlCommand(
#" select acct_no from cust_processing where id = #id ", cx);
cmd.Parameters.AddWithValue("#id", (int)dataRow["ID"]);
cx.Open();
var results = cmd.ExecuteScalar();
if (results != null)
{
dataRow.BeginEdit();
dataRow["ACCT_NO"] = results.ToString();
dataRow.EndEdit();
updateDataItems(); <------ CONCURRENCY ERROR
}
}
The error I am getting is a concurrency error. I think that I have more than one version of the row possibly ? I thought I was making sure that I was on the most recent version of the row by calling updateDataTable(). I am the only user so I know I am creating the problem myself.
Here is my update method which is called when I change pages or save and exit or want to write the commit the data:
void updateDataItems()
{
this.procBindingSource.EndEdit();
this.procTableAdapter.Update(xyzDataSet);
xyzDataSet.AcceptChanges();
}
I have tried executing updateDataItems from various places such as after I assign dataRow["ACCT_NO"] = results.ToString() or before and after assigning that.
I'm pretty much down to guess and check so any thoughts, help and advice will be appreciated and +1.
Okay -- so the problem was that I was trying to update the current row from the program and also using the binding navigator. They were not working together properly.
The solution was to add a text box to the form in the forms designer and set visible = false and bind it to ACCT_NO. Once I got the results from my other form, I just needed to set the .text property of the ACCT_NO textbox to the new value and the binding navigator managed all my updates for me correctly.
txtAcct_No.text = results.ToString();

wxpython SetFocus and EVT_KILL_FOCUS combobox

I am trying to understand how EVT_KILL_FOCUS and SetFocus on a combobox works .Here is the following code:
import wx
class MainWindow(wx.Frame):
count = 1
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, size=(150,150), style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER ^ wx.MAXIMIZE_BOX)
panel = wx.Panel(self, -1)
self.Calc_Display = wx.ComboBox(panel, -1, style=wx.CB_DROPDOWN|wx.TE_PROCESS_ENTER)
self.Calc_Display.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
btn = wx.Button(panel, label="Test")
MainFrameSizer = wx.BoxSizer(wx.VERTICAL)
MainFrameSizer.Add(self.Calc_Display, 0, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER, 5)
MainFrameSizer.Add(btn, 0, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER, 5)
panel.SetSizer(MainFrameSizer)
panel.Fit()
self.Show()
def OnKillFocus(self, event):
print ('EVT_KILL_FOCUS was called %i times' %MainWindow.count)
MainWindow.count += 1
# self.Calc_Display.SetFocus()
event.Skip()
app = wx.App(False)
frame = MainWindow(None, "Test")
app.MainLoop()
If run this, you will get a print every time the combobox loses focus, which is expected.
If you uncomment line 28, that's when it gets weird. The EVT_KILL_FOCUS gets called over and over. That is the behavior I am trying to understand. In the program I am writing, I want to force the combobox to maintain focus in case a condition is not satisfied. Are there any ways around this behavior?
I found this link on the issue, but I did not quite understand it: http://wiki.wxpython.org/Surviving%20with%20wxEVT%20KILL%20FOCUS%20under%20Microsoft%20Windows
Thanks for any help
After reading the link posted in your question, and playing around with your code, I came to the conclusion that calling SetFocus() on the combobox is apparently triggering the EVT_KILL_FOCUS in Windows. I had noticed that on running the program, it prints the statement once, although It shouldn't since the combobox is not losing focus.
I tried two things:
First was to move the combo box code after the button code. In this case when the program is run the Focus is on the button, and sure enough the statement is not printed!
Here's the edit:
btn = wx.Button(panel, label="Test")
self.Calc_Display = wx.ComboBox(panel, -1, style=wx.CB_DROPDOWN|wx.TE_PROCESS_ENTER)
self.Calc_Display.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
Second was to try binding the btn to a handler which sets the focus on the combobox
btn.Bind(wx.EVT_BUTTON, self.On_Button)
def On_Button(self, event):
self.Calc_Display.SetFocus()
In this case the statement was being printed twice every time the button was being clicked. I guess this is once for when the focus is lost and once for setting back the focus. Note that the SetFocus() is still commented out in the OnKillFocus in this case.
Back to your code: If the SetFocus is "uncomment-ed" the statement is printed many times because it keeps setting the focus which in turn triggers the event and it goes on in a loop. This may be a wrong explanation, but nevertheless it is the only thing I could think of.

Clicking checkbox on web page using Applescript

I'm somewhat new to Applescript, and I am trying to make Applescript check a checkbox to select it. I want the checkbox to be clicked regardless of whether or not it's already checked. Here is the checkbox's location according to the Accessibility Inspector:
<AXApplication: “Safari”>
<AXWindow: “Studio”>
<AXGroup>
<AXGroup>
<AXGroup>
<AXScrollArea: “”>
<AXWebArea: “”>
<AXGroup: “”>
<AXCheckBox: “”>
Attributes:
AXRole: “AXCheckBox”
AXSubrole: “(null)”
AXRoleDescription: “check box”
AXChildren: “<array of size 0>”
AXHelp: “”
AXParent: “<AXGroup: “”>”
AXPosition: “x=1104 y=825”
AXSize: “w=18 h=19”
AXTitle: “”
AXDescription: “”
AXValue: “0”
AXFocused (W): “0”
AXEnabled: “1”
AXWindow: “<AXWindow: “Studio”>”
AXSelectedTextMarkerRange (W): “<AXTextMarkerRange 0x101937860 [0x7fff76e43fa0]>{startMarker:<AXTextMarker 0x1019378b0 [0x7fff76e43fa0]>{length = 24, bytes = 0xac01000000000000c0366e23010000001700000001000000} endMarker:<AXTextMarker 0x101938030 [0x7fff76e43fa0]>{length = 24, bytes = 0xac01000000000000c0366e23010000001700000001000000}}”
AXStartTextMarker: “<AXTextMarker 0x101938030 [0x7fff76e43fa0]>{length = 24, bytes = 0xa00000000000000098975e0d010000000000000001000000}”
AXEndTextMarker: “<AXTextMarker 0x1019378b0 [0x7fff76e43fa0]>{length = 24, bytes = 0xa200000000000000405e7812010000000000000001000000}”
AXVisited: “0”
AXLinkedUIElements: “(null)”
AXSelected: “0”
AXBlockQuoteLevel: “0”
AXTopLevelUIElement: “<AXWindow: “Studio”>”
AXTitleUIElement: “(null)”
AXAccessKey: “(null)”
AXRequired: “0”
AXInvalid: “false”
AXARIABusy: “0”
Actions:
AXPress - press
AXShowMenu - show menu
I've tried multiple methods to get this to work, and I haven't been able to. Any help is appreciated.
Your question with the Accessibility Inspector info is not very helpful I am afraid.
It would help if we could see the actual elements of the web page,
Have a look at this page which I found that shows check boxes and the code that makes it up.
Each element has a name and maybe within some other element.
on the page I can use this Applescript/Javascript to check the check1 checkbox.
Hopefully this will give you an idea of how to go about it.
But remember this code snippet is tailored to this page.
Open the web page and run this applescript
tell application "Safari"
set doc to document 1
do JavaScript "document.forms['testform']['check1'].checked = true" in doc
end tell
Update: Applescript GUI
Update:2 take into account "clicked regardless of whether or not it's already checked"
Taking a punt with your Accessibility Inspector. Which is a bit useless (not your fault)
try:
activate application "Safari"
tell application "System Events"
set theCheckbox to (checkbox 1 of group 3 of UI element 1 of scroll area 1 of group 1 of group 1 of group 2 of window 1 of application process "Safari")
set isEnabled to value of theCheckbox as boolean
if not isEnabled then
click theCheckbox
end if
end tell

iOS 6: UITextField textAlignment does not change cursor position

I use an instance of UITextField in which the text is normally aligned to the right, but switches to left alignment when being edited. This is done by calling setTextAlignment: on the editingDidBegin event. Since the update to iOS 6 this behaves strangely: The text alignment is changed correctly from right to left, but the cursor remains at the far right of the text field until some input is performed.
Does anybody know how to restore the expected behaviour so that the cursor moves as well when the alignment is changed?
To give some context: I use the text field to show a value with a unit. The unit is removed during editing and then displayed again after the user hits enter.
Method called on event editingDidBegin:
- (IBAction)textEditingDidBegin:(UITextField *)sender
{
[sender setTextAlignment:NSTextAlignmentLeft];
[sender setText:[NSString stringWithFormat:#"%.0f", width]];
}
Method called on event editingDidEnd:
- (IBAction)textEditingDidEnd:(id)sender
{
[sender setTextAlignment:UITextAlignmentRight];
[sender setText:[NSString stringWithFormat:#"%.0f m", width]];
}
Try resigning the textView as first responder, then make it first responder right after that.
textView.textAlignment = NSTextAlignmentCenter;
[textView resignFirstResponder];
[textView becomeFirstResponder];
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
textField.textAlignment = NSTextAlignmentLeft ;
return YES ;
}
Change the textAlignment before editing did begin. The best place I know to do this is in the UITextFieldDelegate method textFieldShouldBeginEditing.

I cannot prevent user from editing labels in ListView

According to msdn, http://msdn.microsoft.com/en-us/library/bb774798%28VS.85%29.aspx,
returning TRUE prevents user from editing labels.
So I wrote the code below:
Main:
WinMain(...)
{
DialogBox(..., DlgProc)
}
DlgProc:
DlgProc(...)
{
switch(message) {
case WM_NOTIFY:
if((NMHDR *)lParam->code == LVN_BEGINLABELEDIT) {
return TRUE;
return FALSE;
...
}
Still, the labels can be edited. I dont want to cancel the style LVS_EDITLABELS, because sometimes I would like to allow the users edit labels.
Does anyone know the problem? Thank you.
Returning TRUE from a DialogProc() doesn't mean what you think it does. Quoting from the MSDN library article:
Typically, the dialog box procedure should return TRUE if it processed
the message, and FALSE if it did not. If the dialog box procedure
returns FALSE, the dialog manager performs the default dialog
operation in response to the message.
If the dialog box procedure processes a message that requires a
specific return value, the dialog box procedure should set the desired
return value by calling SetWindowLong(hwndDlg, DWL_MSGRESULT, lResult)
immediately before returning TRUE. Note that you must call
SetWindowLong immediately before returning TRUE; doing so earlier may
result in the DWL_MSGRESULT value being overwritten by a nested dialog
box message.

Resources