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

Re: Programming the Windows Forms Datagrid? by Norman

Norman
Fri Mar 02 08:51:29 CST 2007

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

"Philip" <Philip@discussions.microsoft.com> wrote in message
news:04356787-9C74-4F38-96B4-6F7DA3BBF6C6@microsoft.com...
> 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



Re: Programming the Windows Forms Datagrid? by b89

b89
Fri Mar 02 16:33:00 CST 2007

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



"Philip" <Philip@discussions.microsoft.com> wrote in message
news:04356787-9C74-4F38-96B4-6F7DA3BBF6C6@microsoft.com...
> 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