Solved

Need a jump start on a DataGrid

Posted on 2006-11-02
3
193 Views
Last Modified: 2010-04-16
Hi,

I've used DataGrids before with a database.  But i need to format and populate this one by hand.

Can anyone show me what's needed for a simple datagrid with three columns?

Here are the column types: text, double, double
and I'd like the first column to be as wide as 50%, and each of the two equal double columns to be 25%.

I will populate the columns and update them from my own collection. Although I could certainly make a collection that's designed as the data source for this DataGrid if that's easier.

Could you comment on that?

Thanks,
Bob
0
Comment
Question by:ba272
3 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17858189
You could easily just make an in-memory datatable and bind a grid to that. If you think thats a feasible idea let us know and we can provide code samples.
0
 

Author Comment

by:ba272
ID: 17858217
that sounds good.  I was recalling that there's a way to bind an object to a datagrid.  Is that what you mean?

I think that will work well.
0
 
LVL 15

Accepted Solution

by:
ozymandias earned 500 total points
ID: 17858397
                 DataSet data = new DataSet();
                  DataTable table = new DataTable("mytablename");
                  data.Tables.Add(table);
                  table.Columns.Add(new DataColumn("ID", typeof(int)));
                  table.Columns.Add(new DataColumn("FirstName", typeof(string)));
                  table.Columns.Add(new DataColumn("LastName", typeof(string)));
                  DataRow row = table.NewRow();
                  row["ID"] = 1;
                  row["FirstName"] = "John";
                  row["LastName"] = "Smith";
                  table.Rows.Add(row);
                  
                  DataGrid grid = new DataGrid();
                  grid.DataSource = data;
                  grid.DataMember = "mytablename";
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
defining NULL or 0 10 50
Input parameteres to DragOver 2 37
Set custom font WPF 2 21
Using sample Autorize.net c# simple example 1 26
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question