Need help learning Datagrid Basics

Posted on 2007-07-27
Last Modified: 2013-11-07
I am very new to datagrids, so new that I am having a hard time grasping the concept. I would like to teach it to myself with the aid of you, the expert. Currently I am only interested in unbound datagrids.

I have been looking all over the web and can not find any learning material that will help me reach my goal.

I find the best way to learn is by example so will begin by posting a series of questions...starting out simple and progressing forward. I know what I want for an end product but do not want to post a question that is miles long when I do not understand the basics. The bottom line is I want to learn and not just get code so here goes...


I am using VB.Net 2005 SP1 Compact Framework

I have added a datagrid called dgTest to Form1. This has to be unbound. I want to add 4 columns 3 will be textboxes and one will be a combobox.

Col 1 textbox Header Name: Client ID
Col 2 textBox Header Name: First
Col 3 textBox Header Name: Last
Col 4 combobox Header Name: Color

All Columns and Header names are to be visible

The textboxes will be blank but the combobox will have the values of "Red", "Blue", "Orange" and can not accept typed in data. It has to be a selected value.

The total width of the datagrid is 226. I need the width of each column to be 56.

How do I do this?


Question by:PBLack
    LVL 48

    Accepted Solution


    Author Comment

    None of those links answer my question. You see I do not want to add info from a datasource. I want to be able to add user entered data to each row in the datagrid and then add that data to a table later on. Right now I just want to know how to create the datagrid - an empty shell so-to-speak.

    LVL 48

    Expert Comment

    But in this example you can see how insert column and rows by code, without datasource.
    LVL 48

    Expert Comment

    If you understand (more or less) C# you can look for this good guide

    Author Comment

    I tired the following code and was met with errors:

    1) maxColumnNumber is not declared
    2) dataTable is not declared

    Dim newColumnName As String
    Dim index As Integer

    ' Increment the max column number.
    maxColumnNumber += 1

    ' Construct name for new column.
    newColumnName = "C " + maxColumnNumber.ToString()

    ' Create a new column.
    dataTable.Columns.Add(newColumnName, Type.GetType("System.String"))

    ' Add data to each row in the table for the new column.
    For index = 0 To dataTable.Rows.Count - 1
          dataTable.Rows(index)(newColumnName) = "R " + index.ToString() + ", " + newColumnName
    Next index      
    LVL 48

    Expert Comment

    Sorry I'm not in my computer but ...

    You have to declare the variables, so:

    Dim maxColumnNumber As Integer
    Dim dataTable as New DataTable

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now