Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Manually Poplating a DataGrid...

Status
Not open for further replies.

VisualGuy

Programmer
May 27, 2003
162
US
I'm new to VB.NET. I'm used to doing everything in VB6.0 so, I'm confused about how one would manually populate a DataGrid.

In VB6.0 you could do this easily while using an MSFlexGrid. You would simply assign a value to a cell and move your way across the grid, till you called the next line.

I'm aware that you can call a reference to a flexgrid, but I want to know if this is the recommended way. If I need to reference a flexgrid, what is the best way to do this. Otherwise, can someone provide me with an example of how to populate the DataGrid this way, or at least another VB.NET grid that handles this better?
 
I would avoid using the MSFlexGrid from VB 6 in .Net. There are licensing issues that make it a major headache.

I have been using (and am pretty pleased with) the Component One flex grid. The C1 flex grid used to be available on the VB.Net developer tools package from Microsoft. It used to be free/cheap, but I think I heard someone say that they nolonger offer it. You may have to get a copy from C1 (I think they license for ~$600)

The easiest way to manually control the grid is with your own datatable. You can modify the data table how ever you want and then let a Flex Grid display those values to the user.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
I mostly agree with Rick!!!

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Well, I've read that you can use ADO.NET when reading a text file, but I need more control. Isn't there a way, without spending $$, that manually add cells to the grid or any VB.NET grid?
 
Create a DataTable in memory. Create DataColumns for the DataTable. Add rows to the DataTable. Bind the DataTable to the DataGrid.
 
OK, I tried that and it worked:

Dim Tbl As New DataTable()
Dim Col1 As New DataColumn()
Dim Col2 As New DataColumn()
Dim Col3 As New DataColumn
Dim ts As New DataGridTableStyle
Dim r As DataRow


Col1.DataType = System.Type.GetType("System.Int32")
Col1.ColumnName = "Name"
Col1.Caption = "Name"
Col1.ReadOnly = True
Tbl.Columns.Add(Col1)
'Define Column 2
Col2.DataType = System.Type.GetType("System.String")
Col2.ColumnName = "Adress"
Col2.Caption = "Address"
Col2.ReadOnly = True
Tbl.Columns.Add(Col2)
DataGrid1.DataSource = Tbl

r = Tbl.NewRow()
r("Name") = "Bill Sheridan"
r("Address") = "66 Manito Ave."
Tbl.Rows.Add(r)
End Sub


This works well, but I'm having trouble controlling the width of the columns. I want to lock them and set the width manually.
 
I posted this a while back, and still havent got around to making an FAQ of it. It is a Datagrid class which makes it very simple to populate and control column widths and contents

thread796-1029632


Sweep
...if it works dont mess with it
 
Add a TableStyle to the DataGrid, then add GridColumnStyles to control the width.
 
Thank you all, this was a big help. I think I'm getting the hang of it!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top