Tuesday, August 16, 2005

The Internet Explorer Blog explains: http://blogs.msdn.com/ie/archive/2005/08/15/452006.aspx

Did you know that:

A URI consists of multiple components, each of which helps the browser and server to retrieve the requested file.

For example, given the URI http://search.msn.com/results.aspx?q=ie7#listings

  • The scheme component is http
  • The hostname component is search.msn.com
  • The path component is /results.aspx
  • The query component is q=ie7
  • The fragment component is listings

The following URIs are all equivalent:

  • http://www.example.com/sample/
  • http://www.EXAMPLE.com/sample/#
  • Http://www.ex%41mple.com/s%61mple/
  • http://www.example.com/sample/arbitrary/.%2e/
Tuesday, August 16, 2005 7:19:55 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  | 
Sunday, August 14, 2005

This weekend I was pretty procductive. Yesteday I spent the day working on my old truck and getting it running again. It turned out the battery was dead so I bought a new one and the old girl is running like a charm.

Now today, I may clean out the inside and wash the outside and get it ready to be sold. This was my first vehicle and it will be sad to sell it but it can't just sit around here forever! I will probably take a picture with it before I sell it.

You may have already noticed but I finally got around to upgrading my blog to Dasblog version 1.8. I guess the release candidate before this one had some problems so I waited a couple days until the gold release was out.

I also got a Super Nintendo emulator up and running on my Sony PSP. I love playing the same games I did when I was a kid, they were so simple and fun back then!

Sunday, August 14, 2005 8:05:01 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  | 
Thursday, August 11, 2005

Sorry about the bad picture but there was a passed out drunk guy in my usual picture taking spot.

Notice we have Heman working on our condo in the lower left corner so it's bound to turn out ok!

Thursday, August 11, 2005 4:25:42 AM (GMT Standard Time, UTC+00:00)  #    Comments [1]  | 
Tuesday, August 09, 2005

I am upgrading my blog from Dasblog 1.6 to 1.8 tonight so if you notice any weird occurrences please be patient. Thanks.

Tuesday, August 09, 2005 4:37:26 AM (GMT Standard Time, UTC+00:00)  #    Comments [1]  | 
Monday, August 08, 2005
Monday, August 08, 2005 5:40:13 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  | 
Friday, August 05, 2005

Introduction

If you read MSDN you will be hard pressed to find out how to bind a business object to a datagrid. I thought to make up for the lack of business object documentation; I would write a simple tutorial on how to bind an object to a datagrid.

First Create Your Class

First let’s create a normal class nothing fancy:

using System;

namespace Employee
{

 public class Employee
 {
  public Employee()
  {   
  }
  
  #region Employee Accessors
  
  private string _firstName;
  private string _lastName;
  private int _employeeNumber;
  
  public string FirstName
  {
   get
   {
    return _firstName;
   }
   set
   {
    _firstName = value;
   }
  }
  
  
  public string LastName
  {
   get
   {
    return _lastName;
   }
   set
   {
    _lastName = value;
   }
  }
  
public int EmployeeNumber
  {
   get
   {
    return _employeeNumber;
   }
   set
   {
    _employeeNumber = value;
   }
  }
  #endregion
 }
}

Create a collection of your Business Object

The MSDN documentation doesn't give you a concrete example of binding using a business object but they do say that a datagrid is able to bind to anything that implements the IList (single dimension arrays implement the IList interface), IListSource, or IBindingList interfaces.

Reference: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskbindingthedatagridcontroltoanadodataset.asp

So we will make a collection class of Employee objects that implement the IList interface:

using System;

using System.Collections;

namespace Employee

{

      public class EmployeeCollection : CollectionBase

      {

            public Employee this[int index]

            {

                  get

                  {

                        return (Employee)List[index];

                  }

                  set

                  {

                        List[index] = value;

                  }

            }

            public int Add(Employee value)

            {

              return (List.Add(value));

            }

            public int IndexOf(Employee value)

            {

              return (List.IndexOf(value));

            }

            public void Insert(int index, Employee value)

            {

              List.Insert(index, value);

            }

            public void Remove(Employee value)

            {

              List.Remove(value);

            }

            public bool Contains(Employee value)

            {

              return (List.Contains(value));

            }

      }

}

 

Binding to the Employee collection

 

Now you can use the collection and bind to the grid. Using a windows form, here is the code to add an employee to the grid and also to the employee collection:

 

private void btnAddToGrid_Click(object sender, System.EventArgs e)

{

                  Employee Employee = new Employee();

                  Employee.FirstName = txtFirstName.Text;

                  Employee.LastName = txtLastName.Text;

                  Employee.EmployeeNumber = Convert.ToInt32(txtEmployeeNumber.Text);

                  EmployeeCollection.Add(Employee);

                  //Bind to grid here.

                  dataGrid1.DataSource = EmployeeCollection;

                  CurrencyManager cm =

                        (CurrencyManager) this.dataGrid1.BindingContext[EmployeeCollection];

                  if (cm != null)

                  {

                        cm.Refresh();

                  }

            }

 

Here is the code to remove the employee object from the grid and also from the employee collection:

 

                        private void btnRemoveFromGrid_Click(object sender, System.EventArgs e)

            {                       EmployeeCollection.RemoveAt(dataGrid1.CurrentCell.RowNumber);

                  //Bind to grid here.

                  dataGrid1.DataSource = EmployeeCollection;

                  CurrencyManager cm =

                        (CurrencyManager) this.dataGrid1.BindingContext[EmployeeCollection];

                  if (cm != null)

                  {

                        cm.Refresh();

                  }

            }

A good article explaining the pros and cons of datasets can be found at:

http://msdn.microsoft.com/asp.net/default.aspx?pull=/library/en-us/dnaspp/html/CustEntCls.asp

Also the book Expert C# Business Objects goes into more depth than my code example and is a great read.

http://www.lhotka.net

 

Friday, August 05, 2005 3:19:35 PM (GMT Standard Time, UTC+00:00)  #    Comments [1]  | 
Tuesday, August 02, 2005

I read this from the Make website today. Apparently by pressing the “close door” button and the button of the floor you want to go to, you can make certain elevators go into “express” mode where they will take you directly to your floor without any stops bypassing anyone else who may be waiting.

I am going to try this at work today and in any other elevator I get in. I won't really know if this works unless the elevator stops then I know it doesn't work. I love little secrets like this that not a lot of people are aware of.

Tuesday, August 02, 2005 6:13:47 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  | 

Steve Yzerman signed a 1 year deal with the Wings!!! This means he will have at least 1 more year until he will retire. I will have to make sure I go to all the games when the Wings are in town.

Tuesday, August 02, 2005 6:01:40 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  | 
Saturday, July 30, 2005

 

Saturday, July 30, 2005 12:19:01 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]  | 

Theme design by Jelle Druyts

Pick a theme: