How do I make PDF the default export option for a Crystal Report? - crystal-reports

I am working with CrystalDecisions.CrystalReports.Engine.ReportDocument in WinForms in Visual Studio 2008. Right now when the users click the export button the dialog defaults to saving the report as a CrystalReports formatted file. It's possible to change the selector to PDF, but the specific request that I've been given -- and I've searched for too many hours trying to find -- is to make the 'export report' dialog default to PDF format option.
Does anyone know how to do this?

As of CR XI, the only way I know is to replace the export dialog with your own. You can add your own button to the CrystalReportViewer control and hide their export button.
Here's vb.net code to replace the export button with your own button/eventhandler...
Public Shared Sub SetCustomExportHandler(ByVal crv As CrystalDecisions.Windows.Forms.CrystalReportViewer, ByVal export_click_handler As EventHandler)
For Each ctrl As Control In crv.Controls
'find the toolstrip
If TypeOf ctrl Is ToolStrip Then
Dim ts As ToolStrip = DirectCast(ctrl, ToolStrip)
For Each tsi As ToolStripItem In ts.Items
'find the export button by it's image index
If TypeOf tsi Is ToolStripButton AndAlso tsi.ImageIndex = 8 Then
'CRV export button
Dim crXb As ToolStripButton = DirectCast(tsi, ToolStripButton)
'clone the looks of the export button
Dim tsb As New ToolStripButton
With tsb
.Size = crXb.Size
.Padding = crXb.Padding
.Margin = crXb.Margin
.TextImageRelation = crXb.TextImageRelation
.Text = crXb.Text
.ToolTipText = crXb.ToolTipText
.ImageScaling = crXb.ImageScaling
.ImageAlign = crXb.ImageAlign
.ImageIndex = crXb.ImageIndex
End With
'insert custom button in it's place
ts.Items.Insert(0, tsb)
AddHandler tsb.Click, export_click_handler
Exit For
End If
Next
Exit For
End If
Next
'hide the default export button
crv.ShowExportButton = False
End Sub
Then in the click handler you'd show a customized SaveFileDialog and eventually call the ReportDocument.ExportToDisk method. This way you can set the dialog's title and filename to something useful and of course set the default export type.

Related

How to create a custom dialog in VSCode?

I'm developing an extension for VSCode, and I want to display a custom dialog to help the user configure an ini file.
Is it possible to create a custom dialog with labels and inputs?
You cannot create new UI elements, but if you want to get inputs from the user you can use code like below:
let options: InputBoxOptions = {
prompt: "Label: ",
placeHolder: "(placeholder)"
}
window.showInputBox(options).then(value => {
if (!value) return;
answer1 = value;
// show the next dialog, etc.
});
This will use the same UI as the command palette (when you press Ctrl+P, or any of the other commands that open the input box at the top).

In MS Access VBA determine the next control to have focus

Understanding the order of operations, is there a way for an OnExit or OnLostFocus script to know what control was clicked to take that focus?
I have a form that has a list box from which you have to select an item for the the rest of the data entered into the form to be saved, so that control has the focus when you open the form. If you click on any other control without selecting an item from the list, an OnExit gives you a warning that you haven't made a selection.
The problem that creates is, should you open the form and then decide you don't want it, you get that message when you close the form (either with the close button on the form or the built-in closer).
I would like to be able to tell the OnExit that either the close button has been clicked or the form itself is closing, so don't show the no entries message.
Any thoughts would be appreciated.
Not that I know of.
If your form is rather simple(not to many controls.) Move the warning out of the onExit to a sub. Call it from the other controls when they get focus. But not from the Close button.
Dim bDidUserSelectSomething As Boolean
'In the list box
Private sub ListBox1_Click()
'Do some code here
'Set the flag that they did something
bDidUserSelectSomething = True
End sub
'When you enter the other controls, check if they have done what they should have.
Private Sub TextBox1_Enter()
If bDidUserSelectSomething = False Then
'Warning
End If
End Sub
Consider altering your warning check.
Instead of an OnExit() Event of the listbox, add a validation in all other pertinent controls' BeforeUpdate() events. Usually this event is where validation checks are made.
First, build a general function behind the form that calls your warning:
Public Function WarningMessage() As Boolean
If IsNull(Me.Listbox) Then
Msgbox "Please first select an option in listbox.", vbExclamation, _
"MISSING LISTBOX SELECTION"
WarningMessage = True
Else
WarningMessage = False
End If
End Function
Then call the function to each control:
Private Sub cntr1_BeforeUpdate(Cancel As Integer)
Cancel = WarningMessage
End Sub
Private Sub cntr2_BeforeUpdate(Cancel As Integer)
Cancel = WarningMessage
End Sub
...
As you can see from above, if the listbox is null then the message appears and returns True which is passed back to the control's BeforeUpdate() subroutine to cancel the update.
Now, if there are too many controls to make this doable. Consider hiding all relevant controls in Form's OnCurrent() event except the listbox. When listbox is updated, render the other controls visible. Many softwares and web applications run dynamically like this to prevent users from missing important fields.
Private Sub Form_Current()
If IsNull(Me.listbox) Then
Me.ctnrl1.Visible = False
Me.ctnrl2.Visible = False
Me.ctnrl3.Visible = False
...
Else
Me.ctnrl1.Visible = True
Me.ctnrl2.Visible = True
Me.ctnrl3.Visible = True
...
End if
End Sub
Private Sub listbox_AfterUpdate()
Me.ctnrl1.Visible = True
Me.ctnrl2.Visible = True
Me.ctnrl3.Visible = True
...
End Sub

Easy way to add 'copy to clipboard' to GitHub markdown?

Specifically, I have blocks of code for install that I want the user to be able to quickly copy and paste into a terminal. I'd like a button to 'copy to clipboard' for the code block. Since there's a 'copy to clipboard' button for the git clone URLs, I was wondering if I could piggy back off that or if not whether there was some relatively simple I could add to the MD to make this happen. Or is this simply not possible with the processing and 'safication' the MD text goes through?
The copy button is now a reality (May 2021), as tweeted by Nat Friedman
We just added a "Copy" button to all code blocks on GitHub.
Once copied, you can paste it in a markdown document using Fenced code blocks, to create your code block of your own.
```
function test() {
console.log("notice the blank line before this function?");
}
```
I think that it is not what you want, but if you want to copy, you can do it by running the bookmarklet and adding a copy button.
var copy = function(target) {
var textArea = document.createElement('textarea')
textArea.setAttribute('style','width:1px;border:0;opacity:0;')
document.body.appendChild(textArea)
textArea.value = target.innerHTML
textArea.select()
document.execCommand('copy')
document.body.removeChild(textArea)
}
var pres = document.querySelectorAll(".comment-body > pre")
pres.forEach(function(pre){
var button = document.createElement("button")
button.className = "btn btn-sm"
button.innerHTML = "copy"
pre.parentNode.insertBefore(button, pre)
button.addEventListener('click', function(e){
e.preventDefault()
copy(pre.childNodes[0])
})
})

Simple popup or dialog box in Google Apps Script

I'm looking for simple code that adds a popup in my Google Apps Script Ui that comes up when I hit a submit button. The popup box would display a message and have a button to close the popup.
I've looked all over the place - everything seems so complicated and does way more than I need it to do.
This is the current code I have for the submit button.
function doGet() {
var app = UiApp.createApplication();
app.setTitle("My Logbook");
var hPanel_01 = app.createHorizontalPanel();
var vPanel_01 = app.createVerticalPanel();
var vPanel_02 = app.createVerticalPanel();
var vPanel_03 = app.createVerticalPanel();
var submitButton = app.createButton("Submit");
//Create click handler
var clickHandler = app.createServerHandler("submitData");
submitButton.addClickHandler(clickHandler);
clickHandler.addCallbackElement(hPanel_01);
////Test PopUp Panel
var app = UiApp.getActiveApplication();
var app = UiApp.createApplication;
var dialog = app.createDialogBox();
var closeHandler = app.createClientHandler().forTargets(dialog).setVisible(false);
submitButton.addClickHandler(closeHandler);
var button= app.createButton('Close').addClickHandler(closeHandler);
dialog.add(button);
app.add(dialog);
//////
return app;
}
Since UiApp is depreciated, HTMLService should be used to create custom user interfaces.
To prompt simple popup to display a message, use alert method of Ui class
var ui = DocumentApp.getUi();
ui.alert('Hello world');
will prompt simple popup with hello world and an ok button.
To display customized html template in Dialog, use HTMLService to create template and then pass it to showModalDialog method of Ui Class
var html = HtmlService.createHtmlOutput("<div>Hello world</div>").setSandboxMode(HtmlService.SandboxMode.IFRAME);
DocumentApp.getUi().showModalDialog(html, "My Dialog");
HtmlService.createHtmlOutputFromFile allows you to display html that is in a separate file. see the documentation
Have you tried using zIndex? It places the panel above all of your other panels...
var popupPanel = app.createVerticalPanel().setId('popupPanel')
.setVisible(false)
.setStyleAttribute('left', x)
.setStyleAttribute('top', y)
.setStyleAttribute('zIndex', '1')
.setStyleAttribute('position', 'fixed');
x = panel position from the left portion of your app
y = panel position from the top portion of your app
zIndex = the 'layer' your panel will appear on. You can stack panels using '1', '2', '3' etc.
position = your panel will be in a fixed position denoted by (x,y)
Visibility is set to false until you click submit, then have a client handler for your submit button make the popupPanel visible. When you click the button on your popupPanel, have the client handler set visibility to false once again and it will disappear.
One more thing, I noticed you get the active app and then create a new app. You do not need to create a new app...just new panels inside your app.
Hope this helps!
You can use a dialogbox to popup.
Add a button to the dialog-box. Add a client handler that sets the dialog box invisible,once you click the button.
var app = UiApp.createApplication;
var dialog = app.createDialogBox();
var closeHandler = app.createClientHandler().forTargets(dialog).setVisible(false);
var button= app.createButton('Close').addClickHandler(closeHandler);
dialog.add(button);
app.add(dialog);
This should help.
EDIT
Added "()" after .createClientHandler. That should remove issues related to TypeError: Cannot find function createDialogBox in object function createApplication() {/* */}
Popup - use something like this:
var table = app.createFlexTable();
table.setStyleAttribute("position", "absolute");
table.setStyleAttribute("background", "white");
add items to the table and hide and show as needed.

Enter Key for Login Form

I have a search form and a login form on my website. When the enter button is pressed when the login form has focus, the search runs instead of the login. Is there a way to fix this?
I've already tried using a panel around the login form and use defaultbutton, but the loginview errors when I do this.
You could try setting up a keypress event on your login form. Off the top of my head, something like
$('#loginForm').keypress(function (e) {
if(e.keyCode=='13') //Keycode for "Return"
$('#login').click();
}
});
should work, assuming you give appropriate IDs to the elements involved.
If you're talking about HTML, then this suggests tab order (learn more about that here) is relevant or the order in which the forms were created, the behavior depending on the user agent.
could you try adding attributes at run time like this
Login loginControl = (Login)lvLoginView.FindControl("logLogin");
TextBox tbUserName = (TextBox)loginControl.FindControl("UserName");
TextBox tbPassword = (TextBox)loginControl.FindControl("Password");
Button loginButton = (Button)loginControl.FindControl("LoginButton");
tbUserName.Attributes["onKeyPress"] = "KeyDownHandler('" + loginButton.ClientID + "')";
tbPassword.Attributes["onKeyPress"] = "KeyDownHandler('" + loginButton.ClientID + "')";
and some JS:
function KeyDownHandler(btn){
// process only the Enter key
if (event.keyCode == 13) {
// cancel the default submit
event.returnValue = false;
event.cancel = true;
var obj = document.getElementById(btn);
obj.click();
}}
UPDATE
Auto-converted to VB.NET courtesy of telerik
Dim loginControl As Login = DirectCast(lvLoginView.FindControl("logLogin"), Login)
Dim tbUserName As TextBox = DirectCast(loginControl.FindControl("UserName"), TextBox)
Dim tbPassword As TextBox = DirectCast(loginControl.FindControl("Password"), TextBox)
Dim loginButton As Button = DirectCast(loginControl.FindControl("LoginButton"), Button)
tbUserName.Attributes("onKeyPress") = "KeyDownHandler('" + loginButton.ClientID + "')"
tbPassword.Attributes("onKeyPress") = "KeyDownHandler('" + loginButton.ClientID + "')"