Solved

Need a jump start on a DataGrid

Posted on 2006-11-02
3
190 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
Comment Utility
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
Comment Utility
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
Comment Utility
                 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

11 Experts available now in Live!

Get 1:1 Help Now