By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,172 Members | 1,146 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,172 IT Pros & Developers. It's quick & easy.

Datagrid and arraylist

P: n/a
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 #1
Share this Question
Share on Google+
16 Replies


P: n/a
Stoljilcoviz,

What you ask is all very simple when you use a datatable as datasource.

For other collections it is probably as well to do, what depends on your own
knowledge.

Cor
Nov 21 '05 #2

P: n/a
stojilcoviz,

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.

Kerry Moorman
"stojilcoviz" wrote:
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 #3

P: n/a
<Ke**********@discussions.microsoft.com> wrote in
news:5B**********************************@microsof t.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 #4

P: n/a
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.

Cor

Nov 21 '05 #5

P: n/a
"Cor Ligthert" <no************@planet.nl> wrote in
news:ew**************@TK2MSFTNGP12.phx.gbl:
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.


I know. :-(

The problem is that I don't work directly with datas but rather with
objects which contains this datas. Datas in the database are modified via
these objects, not directly.

Probably it's not the best solution but this what I'm asked.
Nov 21 '05 #6

P: n/a
Cor, I am curious as to why you term an arraylist as "heavy arraylist
solution". I wrote my own MuiltiGrid that works well with ArrayLists and
Arrays of Classes, Structures, Datatables, DataSets, and DataViews. It has
all the functionality of the DataGrid plus many extras such as autosizing
columns, etc. except handling relationships for DataTables. It sorts on any
column (property or field) shown, etc. I find it comfortable working with
Arrays but you've got me concerned now since you believe they are Heavey
Solutions.

"Cor Ligthert" 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.

Cor

Nov 21 '05 #7

P: n/a
Dennis,

How many code would your program had when you had used that standard class
from Net?

Cor
Nov 21 '05 #8

P: n/a
Not sure. I built the MultiGrid as a learning experience as well as the fact
that the DataGrid did not handle very well ArrayLists and Arrays of Classes
and Structures nor did it sort them. I have several applications that I am
working on or plan to work on and in the end, I will certainly have less
lines of code than had I tried to adapt the DataGrid to my applications...i
find the DataGrid very limiting in many respects.

I'm still curious as to why you term the ArrayLists a Heavy Solution...are
they slower than DataTables?

"Cor Ligthert" wrote:
Dennis,

How many code would your program had when you had used that standard class
from Net?

Cor

Nov 21 '05 #9

P: n/a
stojilcoviz,
The data grid needs a "list" that implements the IBindingList interface,
specifically IBindingList.SupportsSorting, IBindingList.SortDirection,
IBindingList.SortProperty, IBindingList.ApplySort, IBindingList.RemoveSort,
and IBindingList.IsSorted. 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

"stojilcoviz" <st***********************@libero.it> wrote in message
news:Xn*********************************@193.70.19 2.192...
| <Ke**********@discussions.microsoft.com> wrote in
| news:5B**********************************@microsof t.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 #10

P: n/a
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

P: n/a
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

P: n/a
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.collections.

The datatable uses collections that implement IList.

I hope this helps,

Cor
Nov 21 '05 #13

P: n/a
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.collections.

The datatable uses collections that implement IList.

I hope this helps,


Thanks for the clraification
Doug
Cor


Nov 21 '05 #14

P: n/a
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.SupportsSorting, IBindingList.SortDirection,
IBindingList.SortProperty, IBindingList.ApplySort, IBindingList.RemoveSort,
and IBindingList.IsSorted. 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

"stojilcoviz" <st***********************@libero.it> wrote in message
news:Xn*********************************@193.70.19 2.192...
| <Ke**********@discussions.microsoft.com> wrote in
| news:5B**********************************@microsof t.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

P: n/a
Dennis,
You need to raise events. In the case of the DataSet object model, the
IBindingList.ListChanged 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****@discussions.microsoft.com> wrote in message
news:53**********************************@microsof t.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.SupportsSorting, IBindingList.SortDirection,
| > IBindingList.SortProperty, IBindingList.ApplySort,
IBindingList.RemoveSort,
| > and IBindingList.IsSorted. 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
| >
| > "stojilcoviz" <st***********************@libero.it> wrote in message
| > news:Xn*********************************@193.70.19 2.192...
| > | <Ke**********@discussions.microsoft.com> wrote in
| > | news:5B**********************************@microsof t.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

P: n/a
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.ListChanged 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****@discussions.microsoft.com> wrote in message
news:53**********************************@microsof t.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.SupportsSorting, IBindingList.SortDirection,
| > IBindingList.SortProperty, IBindingList.ApplySort,
IBindingList.RemoveSort,
| > and IBindingList.IsSorted. 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
| >
| > "stojilcoviz" <st***********************@libero.it> wrote in message
| > news:Xn*********************************@193.70.19 2.192...
| > | <Ke**********@discussions.microsoft.com> wrote in
| > | news:5B**********************************@microsof t.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 discussion thread is closed

Replies have been disabled for this discussion.