473,387 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Using DataGrid Without DataSet (unbound)

Wes
I want to use a DataGrid and manually populate the data in the table. Does
anyone know how this is done?? I want to create all the Columns, and then
just add rows as my Program runs. Is there something else I should be using
in C# than a DataGrid.

Thanks for the Help
Nov 16 '05 #1
4 25343
Personnaly I would create an empty datatable or dataset and bind the datagrid
to it.

"Wes" wrote:
I want to use a DataGrid and manually populate the data in the table. Does
anyone know how this is done?? I want to create all the Columns, and then
just add rows as my Program runs. Is there something else I should be using
in C# than a DataGrid.

Thanks for the Help

Nov 16 '05 #2
Add a DataSet from the toolbox to your form. Using the Properties Window, add
a DataTable to the dataSet and add Columns to the DataTable. Or create your
own table at runtime:

dataTable1 = new DataTable("tablename");
dataTable1.Columns.Add("column 1", typeof(String));
dataTable1.Columns.Add("column 2", typeof(String));
dataTable1.Columns.Add("column 3", typeof(int));
To populate your DataTable:

DataRow dataRow = dataTable1.NewRow();
dataRow[ "column 1" ] = "value 1";
dataRow[ "column 2" ] = "value 2";
dataRow[ "column 3" ] = 3;
dataTable1.Rows.Add(dataRow);

or

dataTable1.Rows.Add(new object[]{ "value 1", "value 2", 3 });
Finally, bind your DataTable to your DataGrid:

dataGrid1.SetDataBinding(dataTable1, "");
Best Regards,
Phil.
"Wes" wrote:
I want to use a DataGrid and manually populate the data in the table. Does
anyone know how this is done?? I want to create all the Columns, and then
just add rows as my Program runs. Is there something else I should be using
in C# than a DataGrid.

Thanks for the Help

Nov 16 '05 #3
Wes,

Why not use the DataSet? You can do exactly what you want in code, just
add the columns, and then add rows as needed. Then just bind to the data
set, and the grid will do the rest. A DataSet does not require an
underlying data source in order to be used. It is an in-memory data
structure.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Wes" <We*@discussions.microsoft.com> wrote in message
news:A1**********************************@microsof t.com...
I want to use a DataGrid and manually populate the data in the table. Does
anyone know how this is done?? I want to create all the Columns, and then
just add rows as my Program runs. Is there something else I should be
using
in C# than a DataGrid.

Thanks for the Help

Nov 16 '05 #4
A DataGrid's DataSource will accept any object which implements
IEnumerable (such as an Array or ArrayList), so a simple array of your
objects would be the simplest. Map columns to the properties you want
displayed.

--
Truth,
James Curran
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
(note new day job!)
"Wes" <We*@discussions.microsoft.com> wrote in message
news:A1**********************************@microsof t.com...
I want to use a DataGrid and manually populate the data in the table. Does anyone know how this is done?? I want to create all the Columns, and then
just add rows as my Program runs. Is there something else I should be using in C# than a DataGrid.

Thanks for the Help

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
1
by: Junkguy | last post by:
I'm having difficulty deleting rows from a datagrid. I want to put a "delete" button on a form and achieve the same functionality as hitting the "delete" key on the keyboard for the selected row of...
3
by: Kevin | last post by:
Hi Al I want to add two combobox columns in my datagrid. the one combobox column must be bound to the same datasource that the datagrid is, and the other combobox I just want to populate with a...
0
by: Dave | last post by:
Tried posting in the Winform Forum without much luck, so posting here... After inserting a new data row to a DataTable that is bound to a datagrid, I am unable to change data in a row that is...
2
by: Roy | last post by:
I am very, very new to ASP.NEt and have never done ASP. I have been trying to get a datagrid to work for about 5 days with very limited results. When I use property builder, bind the control, set...
3
by: jaYPee | last post by:
is there a way to know if the form is edited or not after calling addnew? Me.BindingContext(DsStudentCourse1, "Students").AddNew() because i got an error after closing the form. because in my...
17
by: A_PK | last post by:
I have problem databinding the DataGrid with DataView/DataSet after the filter... I create the following proceudre in order for user to filter as many as they want, but the following code is only...
1
by: TonyJ | last post by:
Hello! I just wonder when is it necessary to use unbound datagrid. It's far simpler to use databound datagrid by using the wizard. Can you just point on some particularly example when an...
3
by: Brock | last post by:
I am trying to populate a Crystal Report from data in my DataGrid. The reason for this is that I want the user to be able to change values without updating the database, but still have their...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.