473,387 Members | 1,703 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.

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 #1
16 1996
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
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
<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
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
"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
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
Dennis,

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

Cor
Nov 21 '05 #8
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
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
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.collections.

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.collections.

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.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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
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...
4
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...
2
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...
6
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
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...
0
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...
2
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...
2
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...
0
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,...
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:
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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,...
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.