?
Solved

Need a jump start on a DataGrid

Posted on 2006-11-02
3
Medium Priority
?
196 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

765 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