|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Datagrid and arraylistI'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. 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 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 Show quoteHide quote "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. > <KerryMoor***@discussions.microsoft.com> wrote in
news:5B6F05DE-33F8-40A0-BEE7-F18E0B7CE203@microsoft.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? Show quoteHide quote > 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. Stojilcoviz,
> This would be a solution. You make me really curious, why you want to use a heavy arraylist 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? > where you can create a lightweight datatable solution. Cor
Show quote
Hide quote
"Cor Ligthert" <notmyfirstn***@planet.nl> wrote in I know. :-(news:ew9g67TNFHA.1040@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. 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. 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. Show quoteHide quote "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 > > > > Dennis,
How many code would your program had when you had used that standard class from Net? Cor 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? Show quoteHide quote "Cor Ligthert" wrote: > Dennis, > > How many code would your program had when you had used that standard class > from Net? > > Cor > > > 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 On Wed, 30 Mar 2005 17:41:26 +0200, "Cor Ligthert"
<notmyfirstn***@planet.nl> wrote: >Stojilcoviz, But doesn't the datatable descend from ArrayList which descends from> >> 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. 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. Show quoteHide quote > >Cor > > Doug,
> But doesn't the datatable descend from ArrayList which descends from No the datatable it is a class which derives from system.data, while the > Ilist. > Arraylist derives from system.collections. The datatable uses collections that implement IList. I hope this helps, Cor On Fri, 1 Apr 2005 13:22:01 +0200, "Cor Ligthert"
<notmyfirstn***@planet.nl> wrote: >Doug, Thanks for the clraification> >> 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, Doug Show quoteHide quote > >Cor > 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 Show quoteHide quote "stojilcoviz" <stojilcoviz_leavethiso***@libero.it> wrote in message news:Xns9629B4B61E00Cstojilcovizliberoit@193.70.192.192... | <KerryMoor***@discussions.microsoft.com> wrote in | news:5B6F05DE-33F8-40A0-BEE7-F18E0B7CE203@microsoft.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. | 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.? Show quoteHide quote "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" <stojilcoviz_leavethiso***@libero.it> wrote in message > news:Xns9629B4B61E00Cstojilcovizliberoit@193.70.192.192... > | <KerryMoor***@discussions.microsoft.com> wrote in > | news:5B6F05DE-33F8-40A0-BEE7-F18E0B7CE203@microsoft.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. > | > > > 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 Show quoteHide quote "Dennis" <Den***@discussions.microsoft.com> wrote in message news:5318CA93-D77D-4EAA-B902-BB27BCD7778D@microsoft.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" <stojilcoviz_leavethiso***@libero.it> wrote in message | > news:Xns9629B4B61E00Cstojilcovizliberoit@193.70.192.192... | > | <KerryMoor***@discussions.microsoft.com> wrote in | > | news:5B6F05DE-33F8-40A0-BEE7-F18E0B7CE203@microsoft.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. | > | | > | > | > 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. Show quoteHide quote "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" <Den***@discussions.microsoft.com> wrote in message > news:5318CA93-D77D-4EAA-B902-BB27BCD7778D@microsoft.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" <stojilcoviz_leavethiso***@libero.it> wrote in message > | > news:Xns9629B4B61E00Cstojilcovizliberoit@193.70.192.192... > | > | <KerryMoor***@discussions.microsoft.com> wrote in > | > | news:5B6F05DE-33F8-40A0-BEE7-F18E0B7CE203@microsoft.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. > | > | > | > > | > > | > > > > |
|||||||||||||||||||||||