Basic Datagrid Code

G

Guest

This is for a Win form.

I want the user to select from a drop down box the
license type, and then click the "ADD" button to add a new row to the
datagrid, with the license type in cell 1 for that new row.

I think the best way is to have an array to store the rows, and the datagrid
is binding to the array.

What is the code to setup an array and have the datagrid bind to that array?
What is the code be hide the "Add" button?
 
K

Kevin Yu [MSFT]

Hi Cadel,

In this case, I suggest you bind the DataGrid to a DataTable. Because if
you bind to a string array, the columns in the DataGrid will only bind to
public properties of the string. There is only length property in the
string class which is public. So the string you have selected will not be
shown. Only a Length column will be in the DataGrid.

I suggest you try to create a DataTable and add a single string column to
that table. And then bind to that DataTable. Here's a sample.

DataTable dt = new DataTable();
dt.Columns.Add("LicenseType", typeof(string));
this.dataGrid1.DataSource = dt;

dt.Rows.Add(new object[]{"TypeA"});
dt.Rows.Add(new object[]{"TypeB"});

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

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