Install Windows 7 on a Virtual Machine with VirtualBox

Earlier this month, Microsoft made the Windows 7 beta available for anyone to download and test drive it. Unless you have a spare computer, it can be somewhat inconvenient to test out new operating systems on your main system.  Although it is possible to dual boot Windows 7 with Vista or XP, you may still prefer to install it on a separate machine.  VirtualBox is just the separate machine you’ve been looking for, and it’s free! So, how to install windows 7 on a virtual machine using Virtualbox?
VirtualBox is a free and open source virtualization program. Essentially, it is like having a complete and separate computer within your computer. You can install any operating system on it, including Windows 7. The latest version of VirtualBox (2.1.2) has support for Windows 7, which makes it very easy and convenient to install.
First, you’ll want to download VirtualBox and install it. VirtualBox is available for multiple platforms: Windows, OS X, Linux, and Solaris. During the installation on a Windows system, you may receive a warning that untested software is being installed. Be sure to click continue when those boxes appear, as essential components for VirtualBox to function properly are being installed.
install windows 7 virtualbox
You’ll also need to download the Windows 7 beta. It is a large file, so it may take quite a while to download depending on your connection. The file you will download is a CD disk image. Fortunately, since you’re going to use it on a virtual machine, you won’t have to actually burn it to a CD to use it.
Once you have VirtualBox installed and you have the Windows 7 beta CD image, you’re ready to create your virtual machine amd install Windows 7 beta. Launch VirtualBox and create a new machine. Be sure to select Windows 7 as your operating system.
Windows_7_New_VirtualBox_Machine
Click Next. On the following screen you will select how much memory you would like the virtual machine to have. I believe the minimum requirement for Windows 7 is 1GB of RAM, so be sure to set it to at least 1024MB.
how to install windows 7 beta
Click Next. On the following screen you will create a new virtual drive for the system. I would recommend using the default option of a Dynamically expanding storage. This way you won’t use any more disk space (on your main system) than necessary. Since you’re using a dynamically expanding drive, the size of the disk is somewhat arbitrary. You just want to be sure not to make it too small, so set it to 100GB to be safe.
Once you’re done creating the virtual machine, you’ll need to configure it to use the Windows 7 disk image you downloaded. Select your virtual machine, click Settings, and navigate to the CD/DVD-ROM section. Check the Mount CD/DVD Drive checkbox and click the ISO Image File radio button. Then click the folder icon and then browse to where you saved your ISO image and select it.
Mounting_the_Windows_7_ISO
If you have a multi-core processor, there’s an option you’ll want to enable to speed things up on the virtual machine.  Go to the General section and on the Advanced tab enable the Enable VT-x/AMD-V checkbox. This allows VirtualBox to take advantage of machine virtualization capabilities of your processor, and improves the performance of the virtual machine.
You may also want to add sound to the virtual machine as well. Go to the Audio tab, and click the Enable Audio checkbox and select Windows DirectSound for the Host Audio Driver. Once you have the machine configured, click the Start button to turn on the virtual machine.
You should see the Windows 7 installation begin. Just follow all the prompts and install Windows. If you need to get back to your main computer at any time, the hotkey to release control of the virtual machine is the Ctrl key on the right side of your keyboard.
Once you’ve installed Windows 7, you can install the guest additions. The guest additions will provide better video and audio support to the virtual machine. The guest additions also allow you to better integrate the virtual machine with your main system.
To install the guest additions, press the right Ctrl key on your keyboard, go to the Devices menu and select Install Guest Additions”¦
Install_Guest_Additions
During the guest additions installation, when prompted if you would like to install drivers, click the Install button. Once you’ve installed the guest additions, reboot the virtual machine. Upon rebooting, all of the virtual devices should be working.
Now that you have the guest additions installed, you will be able to share the clipboard, access to files on the main system, and move the cursor seamlessly in and out of the virtual machine. You can press the Right Ctrl-F and see the virtual machine full screen. What a pretty fish!
Have you tried Windows 7 with other free virtualization programs? Did you try to install Windows 7 as a virtual machine with Virtualbox? If so, let us know which ones and what sort of hacks were required to get it to work.

Step-by-Step VMware Server Setup

Most of you out there don’t like to “read the instructions”, I know. However, this article isn’t just going to explain how to install VMware server step by step but also help you to know the “gotchas” when installing VMware server.

Before You Install...

NOTE: This article is based on VMware Server 1.x
VMware Server will run on any standard x86 hardware, including Intel and AMD hardware virtualization assisted systems. The host operating system can be Windows or Linux. This article assumes you are using a Windows XP machine as the host operating system. The most important thing you should know about installing VMware server is that it will use significant amounts of your RAM. You can control the amount of RAM allocated to running virtual servers but it will require a minimum of 256MB per virtual server. Only allocating that much to the virtual servers may be good for your host operating system but will be bad for your virtual servers. Of course, the RAM requirements depend on what you are using the virtual servers for and if you are using the host operating system while you are using the virtual servers. In the end, you need a lot of RAM on your host system to use virtual server.
Fortunately, RAM isn’t that expensive today so I would just make sure you have at least 1GB of RAM to be able to run 1-2 virtual servers. Also, remember that you are running other servers inside your host machine. That means that other things like CPU and disk will also be pushed to their maximum. Even with a lot of RAM, you can easily max out your CPU utilization. Keep these facts in mind so that when your machine slows down, you know where to look. Another tip is just to remember that your machine is not invincible. With a standard desktop today and 1GB of RAM, your performance will seriously suffer if you start more than 1 virtual machine and try to use your host OS at the same time. You can probably run more machines with more RAM but you still need to make sure you limit the number of machines you run at the same time.

Where to Get VMware Server

Before you begin installing VMware Server, you first need to obtain it. Fortunately, for all of us, VMware server is available for FREE. However, even though it is free, you must register to obtain a serial number to use it. To register, go to the Download VMware Server website and don't forget to Register. By registering,
 you will receive a VMWare Server serial number, like this:
Once you have the serial number, copy and paste it to notepad so you can use it later. Now click the Download Now link on that webpage. You will have to click Yes to accept the end user license agreement. On the next screen, click that you want to download the Binary.exe file, like this: Click that you want to Run the executable when the download is completed. When the download is completed, click Run again and the executable will start the VMware Installation Wizard.


How to Install VMware Server

Inside the VMware installation wizard, click Next to get started. Accept the license agreement and click Next. Take the default of a complete installation by clicking Next. If you are running Windows XP as your host operating system, you may get a message like this:

This is because we are using Windows XP as the host operating system and VMware doesn’t recommend running VMware server on a Windows XP desktop (nor do they offer support if you are doing it). However, I haven’t talked to anyone who has had problems doing this, as long as you are only using VMWare Server under Windows XP for app testing & development. Of course, you would not want to run production servers using Windows XP as the host OS. So just click OK on this error and proceed with the installation. Now, take the default destination folder and click Next. If you have autorun enabled on your CDROM drives, you will now see this window:


Because autorun can cause problems when a CDROM with an autorun file is inserted, I recommend taking the default and disabling autorun. Click Next. Finally, click Install to begin the installation. The setup will proceed and VMware server will be installed. As I did, you too may get the following error in the install process:
IIS Vmware Error


For now, click OK on this error. For information on how to handle this error, see the separate article on Starting the VMWare Web Service. This error won’t prevent the installation from being successful. After the installation is complete, you will be asked to provide customer information. Enter your User Name in the box provided. Then go back can copy your serial number from notepad. Now paste that Serial Number in the proper box on the VMware customer information screen. Here is an example:
Enter VMWare customer information


Click Enter, and you will see that the Installation Wizard completed and you must restart your computer.
Once your computer restarts, the installation is completed.

What to Look for After the Installation

After the install is done, what do you do? Well, the first thing you may notice is a VMware Server Console button down on the quick launch section of your taskbar. It looks like this:

You will also have an icon on your desktop for the VMware Server Console. As with most programs, you will have some new icons in your Start menu. Specifically, there are two new icons under Start àVMware à VMware Server. They are VMware Server Console and Manage Virtual Networks
.
If you click on the VMware Server Console button on your taskbar, the console will appear, like this:

Click OK to connect to your local host VMware system (this console can be used to connect to remote VMware servers as well). The first thing you would normally want to do on VMware server is to create a new virtual machine. To begin that process, click on the New Virtual Machine button, like this:

I won’t go into how to create a new virtual machine but the process is pretty self-explanatory. An alternative to creating a new virtual machine is to download a pre-built virtual machine. This can be done through the VMware Virtual Appliance Directory.

Summary

VMware Server is an amazing program and it is even better now that it is free. VMware Server download and installation isn’t difficult but it is important to know the proper steps so that you aren’t just taking your best guess. What is even better is knowing the “gotchas” before they “get you”. This prevents you from spending a lot of time trying to troubleshoot some weird installation error. Best of luck to you in your VMware installation!

C# DataGridView Tips

You want to improve the DataGridView in your Windows Forms application. These improvements can solve usability or aesthetic problems in your DataGridView program. Here we explore DataGridView usage and enhancements in Windows Forms, using the C# programming language.

Use DataGridView 

First, you should use DataGridView when you need to display information that is easily broken up into columns. This will include numbers, names, IDs, and other attributes stored in a database. You can use the Data Source property to hook your DataGridView up to a database, or even an object collection.

Example that sets DataSource [C#]

/// <summary>
/// Used to set up the data table when the user types a query.
/// </summary>
void BuildDataGrid()
{
    dataGridView1.DataSource = GetSearchResults(queryStr);
}

/// <summary>
/// Connect to the database and then use an adapter to
/// fill a DataTable.
/// </summary>
DataTable GetSearchResults(string queryStr)
{
    //
    // Make a new DataTable.
    //
    DataTable table = new DataTable();
    //
    // You will want to declare a new DataAdapter, and then call its fill method
    // on the DataTable.
    //
    return table;
}
Description of DataSource example. After BuildDataGrid is called, the above code sets the DataSource property to the results of another function, GetSearchResults. Next, it performs a custom search. This is custom code that will query a database such as a full-text database for results.
Description of DataTable. It fills a new DataTable. We can use a SqlDataAdapter to fill this DataTable object which we return. Finally, the results appear in your DataGridView.
SqlDataAdapter Example

Use DataAdapters

In the .NET Framework, a DataAdapater class is an object that uses internal logic to take data from a database and into an object. You will need to add that and the SQL statements as well, which depend on what database you are using. This topic is more in the ADO.NET realm, but these are extremely useful in many programs that use DataGridView.

Use objects

Here we use a collection with an implementation of IList, which is an interface shared by Lists and arrays. One great feature is that .NET will read the property names of your collection objects automatically. Simply create a new List or array of objects, and set the DataSource to this.
DataGridView
Example that uses object collection [C#]

/// <summary>
/// The test class for our example.
/// </summary>
class TestObject
{
    public int OneValue { get; set; }
    public int TwoValue { get; set; }
}

void M()
{
    TestObject test1 = new TestObject()
    {
 OneValue = 2,
 TwoValue = 3
    };
    List<TestObject> list = new List<TestObject>();
    list.Add(test1);
    list.Add(test2); // Not shown in code

    dataGridView1.DataSource = list;
}
DataGridView

Hide row headers

You can hide row headers in the DataGridView control by using the RowHeadersVisible property. When you create a new DataGridView, there will be ugly row headers with arrows in the left-most column. These aren't useful for many kinds of applications. Disable row headers by setting RowHeadersVisible to false. This will provide the appearance in the screenshots, which is more streamlined.

Tabbing improvements

You can make tabbing work in your DataGridView control by modifying the StandardTab property in the Visual Studio designer view. This property lets you make sure that when your user tabs around your window, the tabbing events don't get stuck in the DataGridView. Use StandardTab in the designer to make the tab key move out of the DataGridView and to the next control.

Add rows

Here we see how you can add rows to the DataGridView by using the instance Add method in C# code. This method adds rows to the DataGridView programmatically. There is a collection called Rows on the DataGridView. On the rows collection, there is a method called Add. It is usually better to modify the DataSource, but sometimes this approach is useful.
Example that adds rows [C#]

/// <summary>
/// Shows example usage of Add method on Rows.
/// </summary>
void M()
{
    //
    // n is the new index. The cells must also be accessed by an index.
    // In this example, there are four cells in each row.
    //
    int n = dataGridView1.Rows.Add();

    dataGridView1.Rows[n].Cells[0].Value = title;
    dataGridView1.Rows[n].Cells[1].Value = dateTimeNow;

    //
    // The second cell is a date cell, use typeof(DateTime).
    //
    dataGridView1.Rows[n].Cells[1].ValueType = typeof(DateTime);
    dataGridView1.Rows[n].Cells[2].Value = wordCount;
}
Description of Add method. The code example calls Add on Rows. The DataGridView has a Rows collection, which is simply a list of rows in the data grid. Add is an instance method on this collection. It returns an index of the newly added row. The code modifies the new row. Add will give us the index of the new row, so we can modify that row in-place using the regular syntax.
Using ValueType. The code example sets ValueType on cells. Every cell in the data grid has a ValueType property. Usually, you don't need to worry about this. But if you want to specify a DateTime column, you can change it by assigning it to a type, using typeof.
DateTime Examples 
Users can add rows. With the DataGridView control, users can add rows to your program on their own if you do not disallow it. There is a separate article that focuses on managing user-created data in the DataGridView.
DataGridView Add Rows

Configure columns

You will find that Visual Studio provides dialogs that allow you to configure the columns in your DataGridView. Columns are used as templates for how your DataGridView renders columnar data. They do not actually contain the data, just the rules for rendering it to the screen. More information, including a screenshot, is available on this site.
DataGridView Columns, Edit Columns Dialog

Locate current cell

Here we see how you can locate the current cell in your DataGridView by using the CurrentCellAddress property. It returns the cell coordinates, which are also called its location or Point. You can specify X or Y or both, but in this following example, we only take the Y coordinate of the current cell. The current cell is also the selected cell, which usually has a blue highlight.
Example that gets current cell [C#]

/// <summary>
/// Shows example usage of how to get the current cell.
/// </summary>
void M()
{
    //
    // Go from Y coordinate to a selected cell's value.
    // DateTime is just for this example, and the Cells[1] part just
    // takes the second cell for this example.
    //
    int yCoord = dataGridView1.CurrentCellAddress.Y; // You can get X if you need it.
    DateTime thisDate = (DateTime)dataGridView1.Rows[yCoord].Cells[1].Value;
}

Double-clicks

Here we can use the CellDoubleClick event and check RowIndex. In the event handler for CellDoubleClick, call the function you use for when an item is to be used. Note that you must check for e.RowIndex equals -1, which indicates that the column headers were double-clicked and not a regular cell.
Example that handles double-clicking [C#]

void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
    //
    // Do something on double click, except when on the header.
    //
    if (e.RowIndex == -1)
    {
 return;
    }
    ProceedOpen();
}
Events in Visual Studio. As a reminder, click on the DataGridView in the designer, and then look at the Property pane, which is on the right bottom corner usually. Then click on the lightning bolt and scroll down to the CellDoubleClick entry. That's all you have to do to make the event here.

Use SelectionChanged

You can update your program's buttons instantly when the user selects a cell in the DataGridView. Here we need to listen for SelectionChanged and change controls based on the selection. In the functions called in your SelectionChanged code, check for CurrentCellAddress to figure out what was selected and where the selection moved.
Example that uses SelectionChanged [C#]

void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
    //
    // When our selection changes, call the function SetupButtons
    // to make sure "openButton" is always in a valid state.
    //
    SetupButtons();
}

/// <summary>
/// Custom method that sets the Enabled property of a button.
/// </summary>
void SetupButtons()
{
    //
    // Disable openButton when there are no items shown.
    //
    openButton.Enabled = (dataGridView1.RowCount > 0);
}
SelectionChanged event handler. The code uses an event handler. This is triggered whenever the selection changes in the DataGridView. This is convenient because you will want to change the display when the selection is moved.
Using RowCount expression. The code checks RowCount. When RowCount is zero, then nothing is selected, and our user probably can't proceed in your window. This allows us to disable or enable buttons based on what is selected. The user interface will respond instantly when selection is changed. People love it when their programs work better than they have come to expect.
Selection options. The DataGridView has many options for adjusting its selection features. One option I have used a lot is the MultiSelect property; this is described in another article.
MultiSelect Property (DataGridView)

Expand columns

You can specify that the columns in your DataGridView should expand by setting Columns.AutoSizeMode to Fill. This causes the cells to expand to fill the horizontal area. Then, in the designer, set some cells to fixed or percentage width. Just allow one column to fill up the remainder. You will need to do a bit of manual tweaking.

Alternating colors

It is also possible to configure your DataGridView so that the row colors alternate. This is useful for reducing errors caused by rows looking too similar to the program's users. Please check out the tutorial on rows and alternating colors.

Appearance on Vista

Here we see how you can improve the appearance of DataGridView on Windows Vista with some custom conditional code. Windows Vista's DataGridView looks best when it has no border, but Windows XP's looks best with a border. The code returns the appropriate border attributes based on what operating system is running.
Example that improves Vista appearance [C#]

public partial class Form1 : Form
{
    public Form1()
    {
 InitializeComponent();
 dataGridView1.ColumnHeadersBorderStyle = ProperColumnHeadersBorderStyle;
    }

    /// <summary>
    /// Remove the column header border in the Aero theme in Vista,
    /// but keep it for other themes such as standard and classic.
    /// </summary>
    static DataGridViewHeaderBorderStyle ProperColumnHeadersBorderStyle
    {
 get
 {
     return (SystemFonts.MessageBoxFont.Name == "Segoe UI") ?
  DataGridViewHeaderBorderStyle.None :
  DataGridViewHeaderBorderStyle.Raised;
 }
    }
}
DataGridView example

Properties

Here we note that the DataGridView control has hundreds of complex properties. This site has more information on some of these properties in a separate article, although much of the information is not commonly useful.

PreviewKeyDown event

Here we look at what the PreviewKeyDown event on the DataGridView control can be used for. When your DataGridView handles events such as KeyDown, the PreviewKeyDown event can be used to filter some of these events, preventing incorrect behavior. This solves complex problems related to key input.
PreviewKeyDown Event

VB.NET

Here we remember that the VB.NET programming language can use the DataGridView control in the same way as the C# language. The main difference is that the event handlers in the source code have different declarations and VB.NET programs use different default identifiers for Windows Forms controls. This site has a complete tutorial on DataGridView in VB.NET.
DataGridView Usage

More hints

In this section, we look at some miscellaneous tips related to the DataGridView control in Windows Forms and the C# language. These properties and approaches here were useful to me at some point, but are not really important or may not be the best way to do something. If something is really interesting or popular, I will try to expand it.
dataGridView1.Columns[0].HeaderCell.SortGlyphDirection
You can use this to draw that glyph array image. Remember to remove the glyph arrow in ColumnHeaderMouseClick.

BackgroundColor
Setting this to 'Window' often looks best. Looks professional when you adjust this.

SelectionMode
FullRowSelect enum value looks the best when you are displaying simple result rows.

ColumnHeaderMouseClick
This event is used to capture when a header is clicked. Sometimes you may need to modify the direction that the sort glyph is pointing in the column squares. You can check e.ColumnIndex on the event parameter to find out which of the column headers was clicked.

Tutorial

Here we note a related tutorial located on this web site. If you are confused by some aspects of DataGridView that aren't shown here, such as the Columns collections, how to make alternating row colors, or how to use SqlDataAdapter and similar objects, try the DataGridView tutorial.

Summary

Here we saw how you can improve the usability and appearance of the DataGridView in your program with these methods. No one loves developing with DataGridView, but a good one can really make your program shine. DataGridView is ideal in .NET and the C# language for viewing information from databases or object collections.
DataGridView Articles