Solved

Need a jump start on a DataGrid

Posted on 2006-11-02
3
191 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Check my code out(2) 2 54
c# LinkButton OnClientClick 2 34
Combine two datatables into one based on a value from second datatable 4 33
Error on Add method 1 38
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now