473,566 Members | 3,273 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 #1
16 2011
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
"stojilcovi z" 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**********@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 #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******** ******@TK2MSFTN GP12.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.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 #10

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

Similar topics

3
3037
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...
4
3887
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...
2
9911
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...
6
35461
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
1820
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...
0
1349
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...
2
7806
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...
2
2426
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...
0
1239
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...
0
7584
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...
0
8109
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...
0
6263
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5485
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...
0
3643
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...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2085
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
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
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...

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.