473,811 Members | 3,719 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 25377
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("tabl ename");
dataTable1.Colu mns.Add("column 1", typeof(String)) ;
dataTable1.Colu mns.Add("column 2", typeof(String)) ;
dataTable1.Colu mns.Add("column 3", typeof(int));
To populate your DataTable:

DataRow dataRow = dataTable1.NewR ow();
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.SetDa taBinding(dataT able1, "");
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.co m

"Wes" <We*@discussion s.microsoft.com > wrote in message
news:A1******** *************** ***********@mic rosoft.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*@discussion s.microsoft.com > wrote in message
news:A1******** *************** ***********@mic rosoft.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
4118
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 the code that implements managing unbound controls on forms given the superior performance of unbound controls in a client/server environment. I can easily understand a newbie using bound controls or someone with a tight deadline. I guess I need...
1
4187
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 a datagrid. I really want to do it generically so I have subclassed datagrid and made my own delete row method but I can only get it to work for datasources that are datatables or dataviews. Specifically when the datasource is a DataSet I...
3
2420
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 whole lot of values, and then when the user selects a value, I want it to filter the possible values in the other combobox. Is this possible? Also this unbound combobox that hold the whole lot of values, I want to insert it next to the combobox that...
0
3506
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 after the newly added row without getting bizarre results. I have added the full code for the test below. Create a project drop in the code and run. There is nothing crazy about the code. I used the designer to add the dataset and to do the...
2
1422
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 the paging and populate it from the page_load event it works. However, if I set it as unbound, then set the properties through code the grid does not show. I check the dataset count and there are 43 rows. My first question is "Can a datagrid...
3
1851
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 form closing event i have a code to call the EndCurrentEdit to determine if the dataset has changes or not. here is my code in closing event Private Sub Students_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)...
17
2773
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 allow user to filter the first time, when they tried the second time, the speficied cast error message will prompt one.... I create a mydataset1 first, and the mydataset1 data source was getting from DataGrid.DataSource.
1
1989
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 unbound datagrid would be suitable. //Tony
3
2562
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 report reflect the values they anticipate committing to see hypothetical totals of columns from a set of records. These records are displaying properly on my DataGrid but I'm not sure how to get Crystal Reports 10 to use as its datasource the dataset...
0
9731
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10651
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10405
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10136
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7671
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5556
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5697
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.