”’ <summary> ”’ Watermarks the file sOrinignalfilehandle with the content of sWatermarkfilehandle. The resulting ”’ watermarked picture is written to sOriginalfilehandle. ”’ ”’ Returns 1 for success, -1 if the operation can not be performed because of size mismatches ”’ </summary> ”’ <param name=”sOriginalfilehandle”></param> ”’ <param name=”sWatermarkfilehandle”></param> ”’ <remarks></remarks> Private Function WaterMarkFile(ByVal sOriginalfilehandle As String, […]
Month: February 2020
Static class implementing a filecopy function while showing a progress bar
Imports System.IO ”’ <summary> ”’ Copy a file from the source to the target location, and shows a progressbar to the user ”’ ”’ Call: ”’ ”’ CopyFileWithBar.DoCopy(“c:\somesource.bin”,”c:\sometarget.bin”) ”’ ”’ Returns FALSE if the source file does not exists ”’ Returns TRUE if the copy succeeded ”’ You need to trap exceptions for e.g. non […]
Update a winforms control from a background thread
This is the absolute minimum you need to update a control on the GUI thread from a background thread. The key here is the line Invoke(new Action<int>(UpdateGuiText), result); Which will invoke an update on the GUI thread from another thread. The interface consists of a single button and a single textbox. Each click on the […]
Retrieving data from a hidden GridView column
In Visual Studio Winforms applications you can set a column to hidden, and still use it to retrieve data from. If you set a column to inviisble in an ASP.NET application, the column is *not* available to get data from. If you set a column to invisible ad design time, the column is never bound […]
Hiding a control’s commandfield button at runtime
Hiding a command button at runtime can be archieved by casting the commandfield in the DataBound event, and accessing the buttons from there. The sample below shows the hiding of a button based on a security role. protected void DetailsViewDocuments_DataBound(object sender, EventArgs e) { // Check role string currentuser = Common.GetRequestUser(); // some user retrieval […]
Custom DataContext and Query with a Gridview bound to a LinqDataSource
Using an editable grid with a LinqDatasource with a custom connection string and query Binding to a custom datasource Create a custom datacontext object connected to the database to be used; private string _database; private SomeDataContext _dc; protected void Page_Load(object sender, EventArgs e) { _database = Common.GetRequestConnectionString(); _dc = new SomeDataContext(_database); } Catch the contextcreating […]
Setting the column width on a gridview column from code
To set the widht of a column on a GridView in ASP.NET you can hook into the RowDataBound event. This code detects the header line (datacontrolrowtype.header) and then hooks in to set the width of the columns. Instead of percentages you can use any Unit.* measure you like (pixels, mm) VB.NET Example Private Sub GridView1_RowDataBound(ByVal […]
Store and restore the currently selected cell on a datagridview
The standard .NET datagridview has several properties for active selections, but storing and restoring the current location of the user in the grid can be surprisingly un-intuitive. While you can use the SelectedRows propertie to query active selections, re-activating these selections in the rows[] collection, this will not restore focus to the row that was […]
Validation of a detailsview field against a numeric value
Validation of a field inside a detailsview does not need to be done with the Updating or Editing events, but can be accomplished by a simple validation control in the markup language. Convert the field in the detailsview to a template field, and use a standard validation control. <asp:CompareValidator ID=”CompareValidator2″ runat=”server” ErrorMessage=”Numeric input required” Operator=”DataTypeCheck” […]
ENTER key behaviour in ASP.NET
The behaviour of the ENTER key in an ASP.NET application can vary greatly between browsers and versions. Worse: It can change depending on the content of your page. Depending on this browser and version, you may also observe the form getting submitted, but the event handler code not executed… Especialy when using a pagemaster you […]