Jan 25

imagesWhen you are deploying an application that uses the Sql Server Compact Edition, you need to make sure the target machine is able to run the Compact Edition. There are two ways of doing this: a silent way that leaves no trace after uninstalling your application, and the transparent way that installs a separate instance of the Compact Edition.

Continue reading »

Jan 24

imagesThe available official help in using a Sql Server Compact edition in a .Net program is not very extensive. In fact, it does not mention some elemental aspects that you need in order to create a database. This post will show you how to create a new database or connect to an existing one.

I assume you have already downloaded and installed the latest version of the SQL Server Compact edition, and have added a reference to it in your VB.Net project. Also, that you have imported the right namespace (System.Data.SqlServerCe).

Continue reading »

Jan 20

A colleague gave me a zipped Prezi presentation the other day, and when I opened it after unzipping the presentation gave me an error on startup:

image

The error details “id: 2000 the reason is: PreziError id: 2000 the reason is: ErrorEvent ioError Error #2035” do not give much of a clue as to what has happened.

In my case it turned out that two of the pictures used in the presentation had a different filename after zipping and unzipping. Before zipping, both pictures had spaces in their filenames. After zipping and unzipping, those spaces were replaced by ‘%20’ and Prezi could no longer find the pictures.

You can find the pictures used in a presentation in the data\repo folder of the zipped/unzipped presentation. I changed the filenames back to their original value, and the error disappeared.

Jan 05

I’ve had a problem with one of the forms in my solution. The main form, to be precise, which contained a lot of controls and a few user controls. When opening the form in the designer of Visual Studio 2010, it would display a messagebox saying

“Exception of type ‘System.ComponentModel.Design.ExceptionCollection’ was thrown.”

This prevented the designer from showing the form—and me from working on it!

I traced the problem to code contained in two of my user controls. To this yourself, open a second instance of Visual Studio 2010 and attach it to the process of the instance you have your solution in: Alt + Ctrl + P, and choose devenv.exe. The in the Debug menu, go to Exceptions and check both Thrown and User-unhandled boxes for the Common Language Runtime Exceptions. Then go back to the instance with your solution, and try and open the form. The instance that is attached will break on any exception and will give you information on what code exactly raises which exception.

I found that some code attached to my user controls executed during runtime and threw an Object not set to an instance of an object exception. I must admit I do not know why the code executed, but I did find a way to avoid it. Any user control has the property DesignMode, which is True if the control is shown in design mode. Simply put the offending code in between an If..End If block, like so:

If Not Me.DesignMode Then
   ...
End If

Do this for any code that raises the System.ComponentModel.Design.ExceptionCollection exception, and the exception should no longer be thrown when opening the form in the designer!

Dec 19

When developing an application that has a few time-consuming tasks, and a user interface, it may be important to you to keep a responsive interface while still performing that task. Simply calling a method that takes a long time will freeze the GUI and may leave the user thinking the application has crashed. Using threading is the solution to this problem.

And it introduces new difficulties. You can’t access controls on a form from a thread; so showing the user what is happening has to be done in a different way. Keeping the UI responsive is great, but you also want the UI to show some kind of progress of the task at hand.

I’m going to explain 2 ways of doing this. The first, and easy, way is by using the .Net component BackgroundWorker. The second way is to use delegates.

Continue reading »

Apr 29

When designing a read-only cardview for a DevExpress layoutview, you don’t have much choice in the way of word-wrapping the value of a field. The only real customization you have in the way of displaying values, is to designate each field’s value as a specific type (say, Integer, or String).

When you want to display a value that is longer than a single line in one of these fields, there is no clear-cut way to force word-wrap. Fortunately, there is a workaround for this situation, which you can find on the DevExpress forum here. The workaround is this:

  • Go to the In-place Editor Repository in the Designer of the layoutview;
  • Create a new item of type MemoEdit;
  • Assign this control to the ColumnEdit property in the Columns list of the column you want word-wrap for.

image image

image

This is not an obvious workaround, which is why I think it deserves a post.

Mar 04

I’ve had to add a control to a panel in a complicated form, in which many panels overlap and are docked. Working from the VS designer it is not always clear where the focus lies or what control is selected. It’s even worse trying to figure out to which panel control I should add my new control.

So I’ve written a small recursive function that returns a TreeNode object that contains all the controls in their hierarchical structure, starting from the form itself. Together with a form that contains only a TreeView control and takes a TreeNode in its constructor, I could easily find out to which panel I had to add a control and how to dock or anchor it. Here’s the function:

Function CreateTreeNode(ByVal p_objControl As Control) As TreeNode

    Dim l_objTreenode As New TreeNode()
    l_objTreenode.Text = p_objControl.Name

    If p_objControl.HasChildren Then
        For Each l_objSubControl As Control In p_objControl.Controls
            l_objTreenode.Nodes.Add(CreateTreeNode(l_objSubControl))
        Next
    End If

    Return l_objTreenode
End Function

If you then add this node to a TreeView control, you will see how the form’s controls are structured, and you can determine where to add what!

Mar 04

I’ve been looking for a replacement for the VB6 (and QuickBasic) function String$ for ages. Usually I just use PadLeft and PadRight if I can, but sometimes that really isn’t what I want: a string that consists of a specific number of occurences of the same character—almost always a space.

Creating your own method to do this is very straightforward, but today I’ve found a little VB.Net function that does just this! It’s the StrDup function, and it takes two parameters: the number of times you want a character to be repeated, and the character:

Dim l_objFiller As String = StrDup(10, " ")

will give you a string of 10 spaces.