Programming the Windows Forms Datagrid?

G

Guest

Hi,

Using Windows Forms 1.1 (VB.NET)

I have a datagrid on my form and no datasource, just a collection of
Parameters (for a stored procedure selected by the user at runtime) which
have been populated by the user.

I want to display all these parameters in the datagrid so the user can
review them before executing the stored procedure.

How do I dynamically add columns and rows to the datagrid please - I
basically want to loop through the collection of parameters (in this case a
VB Collection containing Oracle Parameter objects, but it can also be SQL
Parameter objects)?

thanks

Philip
 
N

Norman Yuan

You can organise your data (those parameters) in any collection class, which
implements IList or IListSource interface, then bind the data to DataGrid.
 
B

b89

I had the same problem and did it this way:

'-----------------------------------------Beginning of Code---------------

Dim Tbl As New DataTable

Dim Col1 As New DataColumn

Col1.DataType = System.Type.GetType("System.Int32")

'Name of Column

Col1.ColumnName = "No"

'Enabling Auto increment

Col1.AutoIncrement = True

'Col1 header

Col1.Caption = "#"

'Setting Col1 to read only

Col1.ReadOnly = True

'adding col1 to the datatable

Tbl.Columns.Add(Col1)

'repeat the same procedure for each column

'Loading DataGrid1

DataGrid1.DataSource = Tbl

Dim r As DataRow

r = Tbl.NewRow

r("No")=1 'Giving this rows column "No" a value of 1

Tbl.Rows.Add(r)

'-------------------------------------------------------End of
Code-------------------

That should work
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top