• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

Need help learning Datagrid Basics

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?


  • 4
  • 2
1 Solution
PBLackAuthor Commented:
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.

Jorge PaulinoIT Pro/DeveloperCommented:
But in this example you can see how insert column and rows by code, without datasource.
>> http://samples.gotdotnet.com/quickstart/CompactFramework/doc/datagridadding.aspx
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Jorge PaulinoIT Pro/DeveloperCommented:
If you understand (more or less) C# you can look for this good guide http://www.codeproject.com/csharp/PracticalGuideDataGrids1.asp
PBLackAuthor Commented:
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      
Jorge PaulinoIT Pro/DeveloperCommented:
Sorry I'm not in my computer but ...

You have to declare the variables, so:

Dim maxColumnNumber As Integer
Dim dataTable as New DataTable
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now