Archives / 2004 / July
  • Rapid Data Forms Development

    I discovered a quick and dirty way to manipulate DB tables using .Net Windows forms. "Drag and Drop"
    1.  Drag a table from "Server Explorer" and automatically get a connection and dataAdapter object
    2. You can use the dataadapter object to generate a typed datasets
    3. Drop a Datagrid on the form and and set it's datasource to the dataset
    4. Couple of buttons 4 lines of code (bit more if you want lookups as well)
    and you got yourself a pretty neat data entry form for that table.
    Average time to develop per form 5 minutes.
    Also the "Data Form Wizard" is pretty neat too, the only limitation being that it can't seem to handle multiple tables.
    Another useful trick is the Connection and DataAdapter wizards (when you drag connection and adapter objects onto your form) which allow you to generate completely customized objects.
    Looking forward to seeing what improvements are in store in Whidbey.

  • Identity Crisis

    I had  been trying to connect my laptop to my home pc using a cross cable for so many days. Finally yesterday i decided to get it done no matter what.  The problem was that despite all  proper TCP/IP settings the two computers were not able to ping each other. I cleared my ARP cache, reinstalled the cards, changed subnets and IP addresses but to no avail. The green light was flashing on both cards and yet somehow they could not ping each other.
    Well after going through all the settings again and again and again, it finally hit me, both comps were named 'Sijin' , that might be causing the problem. So i renamed my home pc and after a reboot i had two way pinging wooooooot!!! :D :D
    Moral of the day : Give your babies seperate names.

  • ADO.Net powertoys

    Shawn Wildermuth aka ADO guy has a great book on ADO.Net called Pragmatic ADO.Net. It's a definite must read for anyone involved in ADO.Net programming, i have been working with ADO.Net for over a year and yet the book taught me so much, a definite buy. Also i recently used the ADO.Net powertoys to generate my typed datasets. That works great too. Basically the problem is that the methods that the normal typed dataset generator generates are not virtual so if you override the typed dataset then it only hides the base class methods. The ADO power tools has a Typed Dataset generator that defines the methods as virtual and offers other customization abilities. Other than that it has a Utility library of DB functions and a stored procedure generator.

  • Binding problems

    I recently came across a problem in a GUI i had designed. The UI was data bound to an object, now when the user entered some text in a textbox, the change only got propogated back to the object when the user moved the focus away from the textbox. Not acceptable!!  plus if the user happened to press the toolbar save button or use keyboard shortcuts, the value in the textbox was not saved back to the object.
    The problem is that by default, data is written to the source only when the validating event of the control fires.
    The solution i used was to derive a custom textbox
    public class FastValidatingTextBox : TextBox
      protected override void OnTextChanged(EventArgs e)
       base.OnTextChanged (e);
       Binding binding = this.DataBindings["Text"];
       if(binding == null)
    Using this class as soon the text changes the value gets committed back to the object.

  • These controls rock

    Divil has updated his excellent UI controls for .Net. These controls totally blew me away, much more easy to use and way better looking than some commercial controls, and the prices are simply amazing. It's free for non-profit use. The controls include Menu and toolbars which can be docked to any side and have custom renderers, Docking window controls, outlook bar etc. This guy is really a guru of windows forms control development.

  • Interfaces can be both value and reference type

    Yesterday someone posted a message on our user group asking if interfaces were reference or value type. Initially i thought reference type, but then i thought that since value types can implement interfaces too, it needs to be a value type as well.
    I wrote a small code snippet and used propertyGrid control to get visual results :)
    public interface ITest
    public class TestClass : ITest
    public struct TestStruct : ITest
    Here TestClass is a Ref type and TestStruct is a Value type.
    i wrote this code in the Form_load event
    private void Form1_Load(object sender, System.EventArgs e)
    TestClass tc = new TestClass();
    ITest itc = (ITest)tc;
    propertyGrid1.SelectedObject = itc.GetType();
    TestStruct ts = new TestStruct();
    ITest its = (ITest)ts;
    propertyGrid2.SelectedObject = its.GetType();

    When i ran the propertyGrid showed that
    itc.ValueType is 'false' and its.ValueType is 'true'.
    So interface has the same semantics as the type that implements the interface.

  • My session for Delhi .Net User Group

    July session of Delhi .Net UG
    I did  session on advanced data binding in the Windows Forms. Basically i talked about how to setup two-way databinding in Windows Forms, implementing custom collection classes which implement IBindingList. Also i talked about implementations of  IDataErrorInfo, IEditableObject etc. The session was well liked by everyone (I think :) ). Here is the source code for the demo.
    One thing i realized while making the presentation for this demo was that Data Binding is basically an implementation of the MVC architecture for .Net basically the framework is provding the interface for the controller part of the MVC architecture, the model is our object and the views are the forms.
    It was my first talk at a UG meeting and i really enjoyed it. I met the manager of our group Saurabh Verma(an MVP) again, it was Saurabh who had invited me to give the talk. Also i met a lot of core group members of our user group. It was nice to meet so many fellow developers. Being an independednt softwae developer i don't get to meet many of them. :) Looking forward to giving a presentation this month also.