Data Grid

Lanc1988

Well-known member
Joined
Nov 27, 2003
Messages
508
I want to use a data grid to display information, But I cant seem to get more than 1 column on it.. I probably need about 3 columns. So does anyone know if thats possible?
 
Hi,

What a pain this is!

You need to create a new datasource, datatable and then link the datagrid to that and then add your columns and data. If you make the grid read only, that stops users adding rows.

If you need samples, I can post some tonight?

Cheers,
Carl.
 
Hi,

Ill dig out my code (its on my laptop and not my works machine) and post them here for you!

I hacked it from a C example but got it working and it looks "ok"! As long as you make the grid read only!

Cheers,
Carl.
 
Hi,

Sorry for the delay, any how!

Create a new project, add a DataGrid and a button. Put the following code in the button:-

<<<< Start Code >>>>

Dim MyDataSet As New DataSet("MyDataSet")
Dim MyDataTable As New DataTable("MyDataTable")

DataGrid1.ColumnHeadersVisible = True
DataGrid1.DataSource = MyDataTable

MyDataTable.Columns.Add("User ID")
MyDataTable.Columns.Add("User Name")
MyDataTable.Columns.Add("Location")

Dim NewRow As DataRow = MyDataTable.NewRow

NewRow(0) = "CEO"
NewRow(1) = "Carl E. Ogden"
NewRow(2) = "Manchester, England"
MyDataTable.Rows.Add(NewRow)

<<<< End of Code >>>>

I know this is really simple but it works and youll be able to adapt it to your requirements!

Id recommend making the grid read only, this stops users from editing the grid direct and then do what you need to so that you can alter the data.

Hope this helps,
Carl.
 
Back
Top