General discussion

  • Creator
  • #2179044

    All Things .NET


    by benhinton ·

    blog root

All Comments

  • Author
    • #3120444

      Enterprise Library for .NET v2.0

      by benhinton ·

      In reply to All Things .NET

      Over the last year or so Microsoft have been steadily releasing updates for the Enterprise Library. In case anyone doesn’t know what this, have a look at the Patterns msdn site . Basically it’s a collection of classes that provide a wealth of reusable functionality for Data, Caching, Security, Configuration, Logging etc etc. If you haven’t used it up until now, I would deifinitely recommend it!

      Anyway, anyone who has been using the Microsoft Enterprise Library for .NET v1.1 and is keen on switching over to the new version of .NET (v2.0 aka VS.NET 2005) will be interested to hear that there is a prerelease of the new version of the Enterprise Library available on gotdotnet. It can be downloaded here.

    • #3120410

      Internet Explorer ActiveX

      by benhinton ·

      In reply to All Things .NET

      Most of the time I get on pretty well with Microsoft products and in general things tend to stay fairly stable. However, a few weeks ago for some reason unknown to me Internet Explorer decided that it didn’t want to run any ActiveX controls any more. This meant that any site that uses Flash doesn’t work; and site that requires any kind of plugin doesn’t work; and of course, Windows Update doesn’t work.

      The crux of it is that ActiveX is completely disabled. The information bar that is meant to appear has completely vanished. All the information I have found on this problem just simply states resetting the Security settings in Internet Options, but it makes no difference whatsoever.

      I thought I would try and download the beta version of Internet Explorer 7 from MSDN, but unfortunately the Microsoft File Transfer program that manages the download from MSDN requires… you guessed it, and ActiveX control to be installed. So, can’t do that either.

      It seems the only answer is a complete re-install of Windows XP. Drastic, I know – but there really seems to be no other way. So, as usual, when you have a problem with Windows it comes do to the only 2 answers; re-boot and if that doesn’t work, re-install.

      As always if anyone has any suggestions please let me know.

    • #3120407

      C# Synchronised Scrolling RichTextBox Controls

      by benhinton ·

      In reply to All Things .NET

      A week or two ago I spent hours and hours trying to get what I thought would be such a simple thing working. All I wanted to do was have two RichTextBox controls on a Form and have the scrolling of them both syncronized. Doesn’t sound too hard does it?

      However, I very quickly discovered that with .NET v1.1 RichTextBox controls do not expose any events or properties that allow you to manipulate the built in scrollbars programatically. Stupid of me to even think that they would really! So, then I thought that perhaps I could add my own scrollbars to the RichTextBox control using the HScrollBar and VScrollBar controls. Wrong again

      So, then I turned to the Internet and to your friend and mine; Google (oh, and MSDN) which came back with a few helpful tips on using API calls to do the job. It wasn’t ideal but it looked like it would work. The general principal was to create a new control that is derived from RichTextBox. In this new control the idea is fairly straightforward…

      …first you override the WinProc method so we can catch the WM_VSCROLL and WM_HSCROLL messages. Then you create a delegate that can be called to set the scroll position of the other RichTextBox control based on the location of the scrollbar in the current RichTextBox control.

      The API calls in question are: SetScrollPos, GetScrollPos, GetScrollInfo, SetScrollInfo and ScrollWindowEx.

      But could I get it to work properly? No. I could get the scroll bars moving but the contents would not refresh properly.

      After some more intense searching though I stumbled upon an excellent article on thecodeproject that had an implementation specifically for RichTextBox controls. It’s a custom class with a NativeWindow whereby you add as many RichTextBox controls to it and it captures the scroll messages and syncronizes all the other controls. Worked like a charm! I also converted it from VB.NET to C# as the rest of my project was in C#. Basically it all works with one API call:

      [DllImport(“user32.dll”, EntryPoint=”SendMessage”]
      private static extern int SendScrollPosMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref Point lParam);


      Can’t add attachments on here but if you want the code, let me know.

      • #3127655

        C# Synchronised Scrolling RichTextBox Controls

        by joshley2 ·

        In reply to C# Synchronised Scrolling RichTextBox Controls

        I would love the C# code for this!!

        If you could email it to:

        Then I would be incredibly appreciative!

        Thanks very much,

      • #3134196

        C# Synchronised Scrolling RichTextBox Controls

        by thecody ·

        In reply to C# Synchronised Scrolling RichTextBox Controls

        ditto… code would be immensely useful to me as well…

        send to:


      • #3090561

        C# Synchronised Scrolling RichTextBox Controls

        by monique_s80 ·

        In reply to C# Synchronised Scrolling RichTextBox Controls

        This is exactly that I was looking for today. Could you please, please e-mail me the code?


        Bye bye.


      • #3272039

        C# Synchronised Scrolling RichTextBox Controls

        by coleydog ·

        In reply to C# Synchronised Scrolling RichTextBox Controls

        What’s wrong with

        ((Control) richTextBox).Select(); // use the base control’s Select method.

        richTextBox.SelectionIndex = richTextBox.Text.Length // scrolls to the bottom of the control

        Any other value of SelectionIndex will scroll to the appropriate position and with multiple synchronized rtb’s will scroll correctly regardless of their rtb’s sizes.


      • #3273180

        C# Synchronised Scrolling RichTextBox Controls

        by benhinton ·

        In reply to C# Synchronised Scrolling RichTextBox Controls


        Have you actually had that working so that multiple rtb controls are all syncronizing, both vertically and horizontally? I have never managed to get it working apart from the technique used in the code I send you (in the blog). I would be interested to see the code you have used to make it work another way…


    • #3118446

      The Case for Nullable Types

      by benhinton ·

      In reply to All Things .NET

      For a while now I’ve been using some custom Nullable types with .NET 1.1 (located here). Nullable types have now been introduced to the new version of .NET (2.0), and I quite like the way that Microsoft has implemented them.

      The issue with nulls up until now are that value types such as int, long and bool cannot hold a null value. This is simply because only reference types can be null. Even though .NET gives you automatic boxing and unboxing of value types this still doesn’t allow you to assign a null value to it.

      So, whats the problem anyway? Well, consider a database application. A table in a database can define a column of type int, which as far as the database is concerned can either hold an int value or can just be null. So if the value in the database is null how do you reflect this in your class if you can’t assign null to an int? Consider also a bool type. You may have a column in the database of type char (or int, again) and you need to know if its value represents true, false or unspecified. So, a null value can actually be very useful as a tri-state boolean.

      Now, in the following line of code that uses a standard bool type, if the value of the column MobilePhone is null you will get an exception at runtime:

      bool hasMobilePhone = reader.GetBoolean(mobileOrdinal);

      This is because the reader has returned null and you can’t assign it to the value type. So you would have to do something ugly like:

      bool hasMobilePhone = false;
      if (!reader.IsDBNull(mobileOrdinal))
          hasMobilePhone = reader.GetBoolean(mobileOrdinal);
      Not very nice at all! And not only that but if the value was null then the hasMobilePhone variable will contain false which is not representative of the data!

      By using nullable types in C# 2.0 you could just do this:

      bool? hasMobilePhone = reader.GetBoolean(mobileOrdinal);

      The expression bool? declared a value type of bool that can now contain null. You will notice some additional properties on the variable as well. The Value property will give you the underlying value type and HasValue() can be used to query the type and see if there is a value or not. You might wonder why these are needed at all! The answer is that you may rely on this value and you only want to do something if the value is not null. This is achievable because if you use the Value property and the value is actually null, an exception will be thrown – thus not allowing you to use it. This is correct behaviour because if you called Value on a nullable type where the value was in fact null and you were returned zero instead then once again this would not reflecting the correct value of the data.

      There is also a neater way of testing the nullable type using the new expression ??.

      bool? hasMobilePhone = null;

      // Do some processing

      // Output some text
      string output = string.Format(“Mr Big has a mobile? ‘{0}'”, hasMobilePhone ?? “Unspecified”);

      This expression basically means, if hasMobilePhone is actually null, use “Unspecified” instead. If you didn’t do this and the variable was null an exception will be thrown.

      All in all, I think they’re really useful.

    • #3122441

      Installing and Using Team Foundation Server Beta 3

      by benhinton ·

      In reply to All Things .NET

      Well after many hours and three attempts at re-installation I have finally got Team Foundation Server Beta 3 working. I can’t say for sure exactly what the problems were but they seemed to be related to permissions with the user accounts you need to create.

      It’s a complex install because you have to install IIS, SQL Server 2005 and SharePoint Services. The difficulty is that there are little snippets that you have to consider which can easily be missed. For example, with IIS you must not install the Front Page Server extentions. With SQL Server you must install with the default server instance (MSSQLSERVER). If you choose your own instance name, then it won’t work – a most ridiculous constraint if you ask me! Then there is SharePoint Services… don’t touch the configuration page that comes up at the end of the install or you’ll open up a can of worms.

      Even following the installation instructions to the letter didn’t give me a fully working instance. The first time I installed I was getting errors during the installation that SQL Analysis Services couldn’t be accessed as well as a strange error with an Event service (which I think was to do with reporting services permissions). The second time it installed ok but when trying to create a new Team Server project in Visual Studio 2005 it would throw and error. This is not unexpected behavior with a Beta product but the annoying thing was that it didn’t roll back the changes so I was left with 3 source control projects that I couldn’t do anything with and also couldn’t delete!

      The final installation worked and also created the VS.NET 2005 projects. Then I browsed to the project portal page for my new project… unfortunately the panes that show the build status’ etc just showed errors! As you can imagine I was utterly disappointed that after all this time I still hadn’t got a fully working installation. So, this time, rather than complete reinstall I decided that I would try the ‘Repair’ option on the Team Foundation Server setup. And guess what? It all worked!!

      So, I’ve been using VS.NET 2005 with Team Foundation Server Beta 3 for a few days and it’s been going really well. Well, that was until this morning when I opened up my laptop on the train. You see, I was expecting the Visual Studio solution to tell me that I wasn’t connected to the server and offer me the opportunity to work offline. However, this was too much to ask for. Instead, it told me that it could not connect and then gave me the option of temporarily working without source control or removing the binding completely!

      When I got to work, I went to google to see what I could find about setting up Team Foundation Server/VS.NET 2005 for working offline – and do you know what the answer is?? You have two options. 1) Check out the files you want to work on before you disconnect from the internet (which means you have to actually know all the files you plan to work on before you disconnect – highly unlikely!!!), or 2) Manually unselect the ‘readonly’ attribute on each file that you want to work on. With both options you checkout/check in each file accordingly when you reconnect! I was totally dumbfounded that with this product – which is designed for remote working (so Microsoft say) you cannot easily work offline. See the transcript from this interview on MSDN here.

      Hopefully the next Beta/technology preview will be released and will fix some of these bugs/features.

      • #3123729

        Installing and Using Team Foundation Server Beta 3

        by benhinton ·

        In reply to Installing and Using Team Foundation Server Beta 3

        Ok. So when I reconnected it did automatically detect which files were no longer read-only and give me a dialog to check them out. The documentation also says that when it does this it won’t overwrite your files. It seems to work… but I’m standing by my previous moan – that there should be better off-line support!

      • #3113886

        Installing and Using Team Foundation Server Beta 3

        by benhinton ·

        In reply to Installing and Using Team Foundation Server Beta 3

        Further to my last comment I would just like to add, and confirm, that the offline support in Beta3 really does suck! On reconnecting, and getting a dialog for checking the projects out, it did not ‘add to source control’ any of the new files I had added to the project(s). It even missed out a load of files I had modified. So, I am having to manually write down every file I add and edit to make sure I can manually add/checkout when I reconnect….. Microsoft – please release an updated version!!

Viewing 4 reply threads