473,698 Members | 2,434 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datagrid and arraylist

I've a datagrid whose datasource is an arraylist object. The arraylist
holds many instances of a specific class.

I've two questions about this:
1 - Is there a way by which I can obtain a reference to the arraylist item
the current row points to?
2 - Is it possible to sort the grid?

Many thanks in advance.
Nov 21 '05
16 2020
Dennis,

I think that the message from Jay gives a good representation what I want to
say with this.

I used heavy because I often get the response when I ask why people want to
use the arraylist while the datatable fits so nice that the datatable is so
heavy. What is in fact true when you need a one dimensional array. Where it
is for me a normal array when that is static or instead of that an arraylist
when it is dynamic.

However when that does not fit, than I think that there should be taken the
best class for the goals (what can be as well your own a from collectionbase
derived class)

In my opinion is creating all those extra code very heavy. (I was expecting
a question as yours so this I had thought before I wrote that sentence)

In my memory is that I showed you that creating your own strongly typed
dataset is very easy and than you can profit from all that is already
standard build around it.

That does not mean it is not possible to do. I think that even without those
classes I can build all you says. The question for me is, is that efficient,
good maintainable and to understand for others when they have do the
maintenance.

However just my opinion.

Cor

Nov 21 '05 #11
On Wed, 30 Mar 2005 17:41:26 +0200, "Cor Ligthert"
<no************ @planet.nl> wrote:
Stojilcoviz,
This would be a solution.
I hoped that grid sorting could be handled like for datatables (i.e. you
click the column header and the grid is sorted based on the column you
clicked).

Can somebody confirm that this doesn't work on datagrid with arraylist as
datasource?

You make me really curious, why you want to use a heavy arraylist solution
where you can create a lightweight datatable solution.

But doesn't the datatable descend from ArrayList which descends from
Ilist.

I can answer in part your question, if your arraylist is a collection
then you need to specify the name of the collection as the datamember
remebering to get the capitalisation exactly right, the same is true
of the binding of any exposed properties to columns in the datagid.

Sorting depends on whether you have supported iCompare in your class,
that the collection contains.

Cor


Nov 21 '05 #12
Doug,
But doesn't the datatable descend from ArrayList which descends from
Ilist.


No the datatable it is a class which derives from system.data, while the
Arraylist derives from system.collecti ons.

The datatable uses collections that implement IList.

I hope this helps,

Cor
Nov 21 '05 #13
On Fri, 1 Apr 2005 13:22:01 +0200, "Cor Ligthert"
<no************ @planet.nl> wrote:
Doug,
But doesn't the datatable descend from ArrayList which descends from
Ilist.

No the datatable it is a class which derives from system.data, while the
Arraylist derives from system.collecti ons.

The datatable uses collections that implement IList.

I hope this helps,


Thanks for the clraification
Doug
Cor


Nov 21 '05 #14
Jay, in my MultiGrid that I wrote, I still have a couple of issues I'm trying
to work and maybe you can give me some adivce. When I bind to an ArrayList,
I have it worked so that if a Cell in the Grid is edited the Arraylist is
updated. However, if one of the property or field values is changed in one
of the Arraylist elements outside the Grid, I can't seem to figure out how to
get the grid to sense the change except for the user to call an update method
of the Grid which refreshes all the Grid. Is there any way in my grid to
detect a change in an ArrayList property such I can for a DataTable, Dataset,
etc.?

"Jay B. Harlow [MVP - Outlook]" wrote:
stojilcoviz,
The data grid needs a "list" that implements the IBindingList interface,
specifically IBindingList.Su pportsSorting, IBindingList.So rtDirection,
IBindingList.So rtProperty, IBindingList.Ap plySort, IBindingList.Re moveSort,
and IBindingList.Is Sorted. One such class is the DataView class. Another is
the classes found in CSLA .NET http://www.lhotka.net/

Unfortunately ArrayList itself does not implement IBindingList. With effort
one could create a class that implements a IBindingList wrapper over an
ArrayList. One of the projects I've worked on we took such an approach,
unfortunately I don't have a sample of that code readily available.

Lhotka's book "Expert One-on-One - Visual Basic .NET Business Objects"
covers CSLA .NET & includes an example of implementing IBindingList that
supports sorting. NOTE: You can download the source to CSLA .NET at the
above site.

Hope this helps
Jay

"stojilcovi z" <st************ ***********@lib ero.it> wrote in message
news:Xn******** *************** **********@193. 70.192.192...
| <Ke**********@d iscussions.micr osoft.com> wrote in
| news:5B******** *************** ***********@mic rosoft.com:
|
| This would be a solution.
| I hoped that grid sorting could be handled like for datatables (i.e. you
| click the column header and the grid is sorted based on the column you
| clicked).
|
| Can somebody confirm that this doesn't work on datagrid with arraylist as
| datasource?
|
|
| > Assuming that the datagrid is displaying the arraylist items in the
| > order that they exist in the arraylist, you can use the datagrid's
| > CurrentRowIndex as an index to the arraylist's Item property. This
| > will let you obtain a reference to the object in the arraylist.
| >
| > You could sort the datagrid by sorting the arraylist.
| >
| >> I've a datagrid whose datasource is an arraylist object. The
| >> arraylist holds many instances of a specific class.
| >>
| >> I've two questions about this:
| >> 1 - Is there a way by which I can obtain a reference to the arraylist
| >> item
| >> the current row points to?
| >> 2 - Is it possible to sort the grid?
| >>
| >> Many thanks in advance.
|

Nov 21 '05 #15
Dennis,
You need to raise events. In the case of the DataSet object model, the
IBindingList.Li stChanged event notifies the DataGrid that a property of an
item changed via the ListChangeType. ItemChanged value. As I stated earlier I
don't have my sample handy when I did it. I want to say that my objects
raised a Changed event, which my "list" handled, then the "list" raised the
ItemChanged event to notify the datagrid.

I'm heading into a rather busy weekend, I will see if I can find more info
first part of next week...

Hope this helps
Jay

"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:53******** *************** ***********@mic rosoft.com...
| Jay, in my MultiGrid that I wrote, I still have a couple of issues I'm
trying
| to work and maybe you can give me some adivce. When I bind to an
ArrayList,
| I have it worked so that if a Cell in the Grid is edited the Arraylist is
| updated. However, if one of the property or field values is changed in
one
| of the Arraylist elements outside the Grid, I can't seem to figure out how
to
| get the grid to sense the change except for the user to call an update
method
| of the Grid which refreshes all the Grid. Is there any way in my grid to
| detect a change in an ArrayList property such I can for a DataTable,
Dataset,
| etc.?
|
| "Jay B. Harlow [MVP - Outlook]" wrote:
|
| > stojilcoviz,
| > The data grid needs a "list" that implements the IBindingList interface,
| > specifically IBindingList.Su pportsSorting, IBindingList.So rtDirection,
| > IBindingList.So rtProperty, IBindingList.Ap plySort,
IBindingList.Re moveSort,
| > and IBindingList.Is Sorted. One such class is the DataView class. Another
is
| > the classes found in CSLA .NET http://www.lhotka.net/
| >
| > Unfortunately ArrayList itself does not implement IBindingList. With
effort
| > one could create a class that implements a IBindingList wrapper over an
| > ArrayList. One of the projects I've worked on we took such an approach,
| > unfortunately I don't have a sample of that code readily available.
| >
| > Lhotka's book "Expert One-on-One - Visual Basic .NET Business Objects"
| > covers CSLA .NET & includes an example of implementing IBindingList that
| > supports sorting. NOTE: You can download the source to CSLA .NET at the
| > above site.
| >
| > Hope this helps
| > Jay
| >
| > "stojilcovi z" <st************ ***********@lib ero.it> wrote in message
| > news:Xn******** *************** **********@193. 70.192.192...
| > | <Ke**********@d iscussions.micr osoft.com> wrote in
| > | news:5B******** *************** ***********@mic rosoft.com:
| > |
| > | This would be a solution.
| > | I hoped that grid sorting could be handled like for datatables (i.e.
you
| > | click the column header and the grid is sorted based on the column you
| > | clicked).
| > |
| > | Can somebody confirm that this doesn't work on datagrid with arraylist
as
| > | datasource?
| > |
| > |
| > | > Assuming that the datagrid is displaying the arraylist items in the
| > | > order that they exist in the arraylist, you can use the datagrid's
| > | > CurrentRowIndex as an index to the arraylist's Item property. This
| > | > will let you obtain a reference to the object in the arraylist.
| > | >
| > | > You could sort the datagrid by sorting the arraylist.
| > | >
| > | >> I've a datagrid whose datasource is an arraylist object. The
| > | >> arraylist holds many instances of a specific class.
| > | >>
| > | >> I've two questions about this:
| > | >> 1 - Is there a way by which I can obtain a reference to the
arraylist
| > | >> item
| > | >> the current row points to?
| > | >> 2 - Is it possible to sort the grid?
| > | >>
| > | >> Many thanks in advance.
| > |
| >
| >
| >
Nov 21 '05 #16
Yes, I can do it if I raise my own event and handle it in my User Grid Class.
That's what I do now. However, I was hoping that there was some way that
the arraylist could act like a datatable. When the DataTable is changed, I
can intercept either the DataTable RowChanged, ColChanged, etc. or set up a
currencyManger and use the Itemchanged event. I can't seem to find where the
arraylist has any event like these unless I create my own.

"Jay B. Harlow [MVP - Outlook]" wrote:
Dennis,
You need to raise events. In the case of the DataSet object model, the
IBindingList.Li stChanged event notifies the DataGrid that a property of an
item changed via the ListChangeType. ItemChanged value. As I stated earlier I
don't have my sample handy when I did it. I want to say that my objects
raised a Changed event, which my "list" handled, then the "list" raised the
ItemChanged event to notify the datagrid.

I'm heading into a rather busy weekend, I will see if I can find more info
first part of next week...

Hope this helps
Jay

"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:53******** *************** ***********@mic rosoft.com...
| Jay, in my MultiGrid that I wrote, I still have a couple of issues I'm
trying
| to work and maybe you can give me some adivce. When I bind to an
ArrayList,
| I have it worked so that if a Cell in the Grid is edited the Arraylist is
| updated. However, if one of the property or field values is changed in
one
| of the Arraylist elements outside the Grid, I can't seem to figure out how
to
| get the grid to sense the change except for the user to call an update
method
| of the Grid which refreshes all the Grid. Is there any way in my grid to
| detect a change in an ArrayList property such I can for a DataTable,
Dataset,
| etc.?
|
| "Jay B. Harlow [MVP - Outlook]" wrote:
|
| > stojilcoviz,
| > The data grid needs a "list" that implements the IBindingList interface,
| > specifically IBindingList.Su pportsSorting, IBindingList.So rtDirection,
| > IBindingList.So rtProperty, IBindingList.Ap plySort,
IBindingList.Re moveSort,
| > and IBindingList.Is Sorted. One such class is the DataView class. Another
is
| > the classes found in CSLA .NET http://www.lhotka.net/
| >
| > Unfortunately ArrayList itself does not implement IBindingList. With
effort
| > one could create a class that implements a IBindingList wrapper over an
| > ArrayList. One of the projects I've worked on we took such an approach,
| > unfortunately I don't have a sample of that code readily available.
| >
| > Lhotka's book "Expert One-on-One - Visual Basic .NET Business Objects"
| > covers CSLA .NET & includes an example of implementing IBindingList that
| > supports sorting. NOTE: You can download the source to CSLA .NET at the
| > above site.
| >
| > Hope this helps
| > Jay
| >
| > "stojilcovi z" <st************ ***********@lib ero.it> wrote in message
| > news:Xn******** *************** **********@193. 70.192.192...
| > | <Ke**********@d iscussions.micr osoft.com> wrote in
| > | news:5B******** *************** ***********@mic rosoft.com:
| > |
| > | This would be a solution.
| > | I hoped that grid sorting could be handled like for datatables (i.e.
you
| > | click the column header and the grid is sorted based on the column you
| > | clicked).
| > |
| > | Can somebody confirm that this doesn't work on datagrid with arraylist
as
| > | datasource?
| > |
| > |
| > | > Assuming that the datagrid is displaying the arraylist items in the
| > | > order that they exist in the arraylist, you can use the datagrid's
| > | > CurrentRowIndex as an index to the arraylist's Item property. This
| > | > will let you obtain a reference to the object in the arraylist.
| > | >
| > | > You could sort the datagrid by sorting the arraylist.
| > | >
| > | >> I've a datagrid whose datasource is an arraylist object. The
| > | >> arraylist holds many instances of a specific class.
| > | >>
| > | >> I've two questions about this:
| > | >> 1 - Is there a way by which I can obtain a reference to the
arraylist
| > | >> item
| > | >> the current row points to?
| > | >> 2 - Is it possible to sort the grid?
| > | >>
| > | >> Many thanks in advance.
| > |
| >
| >
| >

Nov 21 '05 #17

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

Similar topics

3
3049
by: Stephen | last post by:
I've got a datagrid with a remove button and I would like to add some code in the code behind page so as whenthe button is clicked the corresponding row in the datagrid is removed. The Datagrid is populated by the items in an arraylist shown in the code below. When the button is clicked I would also like the code to remove the items from the Arraylist. I've very little experience working with datagrids and arraylists so im finding this...
4
3899
by: Stephen | last post by:
I have got an event below to remove items from an arraylist and then to rebind the arraylist to the datagrid subsequently deleting the appropriate row. My problem is that my code makes sense and I think my logic seems fine but when I click the button on my datagrid nothing seems to happen. Have you any idea where Im going wrong. Was thinking it might have something to do with my page load/ postback but not really sure. Can someone please...
2
9921
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell (multi-select without modifier keys). I got that working fine, but I also wanted to keep rows selected after a sort, which I do by storing the row's id in an arraylist. The idea was to do the sort and then go back and re-select the rows with that...
6
35476
by: Dan | last post by:
I'd like to loop through selected datagrid rows and extract specified columns from those rows. How would I do that? Thanks... Dan
0
1832
by: Empire City | last post by:
I have an ASP.NET form with a DataGrid and Button. I want to put a RadioButtonList in a DataGrid cell. I bind it to an ArrayList which has a ListItem in the cell. The display part works fine. I then check some boxes and hit the submit button. I can't seem to get the value that is selected on the RadioButton List. I don't want to use the EditTemplate thing I just want to click on the radiobutton and submit the form. I also don't want to do...
0
1357
by: Stephen | last post by:
I have a datagrid with a remove button and I would like to add some code in the code behind page so as whenthe button is clicked the corresponding row in the datagrid is removed. The Datagrid is populated by the items in an arraylist shown in the code below. When the button is clicked I would also like the code to remove the items from the Arraylist. I've very little experience working with datagrids and arraylists so im finding this...
2
7809
by: Stephen | last post by:
I am trying to delete a row in a datagrid on the onclick of a asp:ButtonColumn. The datagrid is created from the items in an arraylist so what im trying to do is remove the item from the array and then rebind the datagrid. Below is the code I have to delete the items from the arraylist but nothing seems to happen when I run this code. Does any one have any idea where Im going wrong. Thanks for any help you can give me. private void...
2
2432
by: Bob Hollness | last post by:
Hi group. I am a newbie to ASP.NET as you will see from some of the questions I may ask! I have a datagrid which I have populated from a database. It works great! I have added a column, via the Columns dialog box from the properties of the datagrid, on the left that contains a select button. So now, when you press the button the whole row is highlighted. Now, what I want to do is have the user highlight as many rows as they wish...
0
1259
by: Marcus Kwok | last post by:
I am having a weird problem with my DataGrid that is bound to an ArrayList. My situation is as follows: I have two DataGrids on a modal form. The top grid populates an ArrayList from a file, then the datagrid is bound to it, and it works fine. The bottom DataGrid is bound to a different ArrayList that holds the same type as the first ArrayList. Both DataGrids are set to Read-Only. The user selects a row from the top DataGrid, then...
0
8604
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9160
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...
0
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6521
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
4370
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
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.