473,385 Members | 1,465 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,385 software developers and data experts.

use of datagrid for non database project

Can anyone tell me please if its possible to bind a datagrid to an array of
objects (defined by me) so that when i update the contents of the array, the
data grid updates its display.

Any tips would be greatly appreciated.

Greg.
Nov 17 '05 #1
4 1320
You actually don't have to connect it to a database. All the data-aware controls can
be connected to disconnected datasets, which you can eumlate in code. It requires you
to create the correct type of list, however. I don't have any example handy, but you
should be able to find one pretty easy. Basically you create a dataset with:
DataSet dsCustomers = new DataSet();

Then do something like:

dgCustomers.DataSource = dsCustomers;
dgCustomers.DataMember = "Customers";

where dlgCustomers is the datagrid. The main problem you have is that a dataset can have multiple tables in it, and you need to create and fill just one of them. In this case you are telling the grid to use the "Customers" table in the dataset dsCustomers. I don't, off hand, remember how to fill the dataset in code. I know you will have to create the table within the dataset, and then fill it. Search help for dataset for starters.

-- Larry Maturo


"Greg Williams" <no***********@home.com> wrote in message news:dk**********@news.freedom2surf.net...
Can anyone tell me please if its possible to bind a datagrid to an array of
objects (defined by me) so that when i update the contents of the array, the
data grid updates its display.

Any tips would be greatly appreciated.

Greg.

Nov 17 '05 #2
Actually, you don't need a DataSet at all. Anything which implements
IList should suffice (such as ArrayList). The trick is that the objects
stored in the IList must have public properties for each column you want
display. If you want to use Column mapping, it gets trickier, but it can
be done. You need to use the name of the type of the collection (eg
"ArrayList") as you would the table name if it were a DataSet.

--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
"Greg Williams" <no***********@home.com> wrote in message
news:dk**********@news.freedom2surf.net...
Can anyone tell me please if its possible to bind a datagrid to an array of objects (defined by me) so that when i update the contents of the array, the data grid updates its display.

Any tips would be greatly appreciated.

Greg.

Nov 17 '05 #3
Thanks James and Larry.
I managed to get the thing working with just one line of code -
frightengly simple!

this.dgMyDataGrid.SetDataBinding(arrMyArrayOfObjec ts, null);

All my data was displayed correctly!

Thanks again.

Greg.

Nov 17 '05 #4
Greg wrote:
I managed to get the thing working with just one line of code -
frightengly simple!

this.dgMyDataGrid.SetDataBinding(arrMyArrayOfObjec ts, null);


Actually, it should be even simplier:

this.dgMyDataGrid.DataSource = arrMyArrayOfObjects;

--
Truth,
James Curran [erstwhile-MVP]
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
Nov 17 '05 #5

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

Similar topics

7
by: Billy Jacobs | last post by:
I am using a datagrid to display some data. I need to create 2 header rows for this grid with columns of varying spans. In html it would be the following. <Table> <tr> <td colspan=8>Official...
2
by: John Latten | last post by:
Hi there, I have got a problem when adding extra (= dummy) columns to a datagrid. I have a datagrid that is bound to a datatable. The datatable is filled with data from a SQL Server 2000...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
1
by: glenn | last post by:
Hi folks, I need to have two ddl's in one DataGrid cell. The first ddl has a list of company names and the second has a list of contact names that work in the company name that was selected in...
0
by: Viper | last post by:
Hey, I'm having a ennoying problem with VB.NET. The solution will probably very simple but I can't find it. I'm having an Access2003 database (called Database.mdb) with one Table 'Person'. I'm...
0
by: sathyan8294 | last post by:
i am using vb.net 2003.i am doing my project in vb.net windows application. how do i remove selected row permanently from sql database through datagrid in vb.net windows form during runtime. for...
1
navanova
by: navanova | last post by:
I am doing my project in vb.net windows application and SQL Server 2000. how do i remove selected row permanently from sql database through datagrid in vb.net windows form during runtime. for...
4
by: madho | last post by:
I am doing my project in vb.net windows application and SQL Server 2000. how do i remove selected row permanently from sql database through datagrid in vb.net windows form during runtime. for...
8
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...
17
lee123
by: lee123 | last post by:
I know this is a free site and the moderators or anybody don't have to answer if they don't want to.. but if there is someone who knows how to answer this question please help with this one. i...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.