PC Review


Reply
Thread Tools Rate Thread

Datagrid and arraylist

 
 
stojilcoviz
Guest
Posts: n/a
 
      30th Mar 2005
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.
 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      30th Mar 2005
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


 
Reply With Quote
 
=?Utf-8?B?S2VycnkgTW9vcm1hbg==?=
Guest
Posts: n/a
 
      30th Mar 2005
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.
>

 
Reply With Quote
 
stojilcoviz
Guest
Posts: n/a
 
      30th Mar 2005
<(E-Mail Removed)> wrote in
news:5B6F05DE-33F8-40A0-BEE7-(E-Mail Removed):

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.


 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      30th Mar 2005
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



 
Reply With Quote
 
stojilcoviz
Guest
Posts: n/a
 
      30th Mar 2005
"Cor Ligthert" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> 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.
 
Reply With Quote
 
=?Utf-8?B?RGVubmlz?=
Guest
Posts: n/a
 
      31st Mar 2005
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
>
>
>
>

 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      31st Mar 2005
Dennis,

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

Cor


 
Reply With Quote
 
=?Utf-8?B?RGVubmlz?=
Guest
Posts: n/a
 
      1st Apr 2005
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
>
>
>

 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      1st Apr 2005
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" <stojilcoviz_leavethisout_@libero.it> wrote in message
news:Xns9629B4B61E00Cstojilcovizliberoit@193.70.192.192...
| <(E-Mail Removed)> wrote in
| news:5B6F05DE-33F8-40A0-BEE7-(E-Mail Removed):
|
| 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.
|


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot bind an arraylist to a datagrid asp.net Farook Microsoft ADO .NET 0 23rd Jan 2008 05:33 AM
DataGrid and ArrayList Jarsinio Microsoft VB .NET 1 1st Jan 2007 03:10 AM
arraylist inside an arraylist for datagrid, gridview rjl Microsoft C# .NET 4 13th Apr 2006 07:32 PM
Binding DataGrid To ArrayList Rami Microsoft VB .NET 5 6th Feb 2005 09:54 PM
arraylist and datagrid Steph Microsoft Dot NET Framework Forms 0 8th Apr 2004 08:40 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:13 PM.