473,667 Members | 2,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ArrayList of custom classes as Datagrid's DataSource

Hi guys, I've been reading several topics that talk about creating a
custom collection to use it as DataSource of a Datagrid.

But the fact is I have a class called Action and another class called
Profile. In my application, the user assigns several Actions to a
Profile. I thought doing this using an ArrayList of Actions and puting
that as the DataSource of the Datagrid that shows the assignments. It
works, but it shows every property Action class have.

My two questions are:
1) how can I choose the properties of Action class I want to be
bounded?
2) does it sound reasonable? I mean the ArrayList of my custom class
Action...

Thanks in advance,
Damian

Nov 17 '05 #1
5 2097
Hi,

Is this a web or win app ?
I have done this for a web app, don't think it will work in a win app
though.
Here is the code:

You see I have to cast the DataItem to teh correct type to have access to
the properties

<asp:templateco lumn ItemStyle-VerticalAlign=" Top" ItemStyle-Width="117"
ItemStyle-HorizontalAlign ="left" >
<itemtemplate >
<span ><%# ((CtpRecord)Con tainer.DataItem ).Locations.Cou nt==0?"Not set":
((CtpRecord)Con tainer.DataItem ).Locations[0].LocalName%></span>
</itemtemplate>
</asp:templatecol umn>

This is a column which require some extra processing hence I use a method
declared as protected string GetFirstDocumen tOfRecord in the code behind

<asp:templateco lumn ItemStyle-VerticalAlign=" Top" ItemStyle-Width="110"
ItemStyle-HorizontalAlign ="left" >
<itemtemplate >
<span ><%# GetFirstDocumen tOfRecord((CtpR ecord)Container .DataItem)
%></span>
</itemtemplate>
</asp:templatecol umn>
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

<dl******@gmail .com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
Hi guys, I've been reading several topics that talk about creating a
custom collection to use it as DataSource of a Datagrid.

But the fact is I have a class called Action and another class called
Profile. In my application, the user assigns several Actions to a
Profile. I thought doing this using an ArrayList of Actions and puting
that as the DataSource of the Datagrid that shows the assignments. It
works, but it shows every property Action class have.

My two questions are:
1) how can I choose the properties of Action class I want to be
bounded?
2) does it sound reasonable? I mean the ArrayList of my custom class
Action...

Thanks in advance,
Damian

Nov 17 '05 #2
Hi,

Is this a web or win app ?
I have done this for a web app, don't think it will work in a win app
though.
Here is the code:

You see I have to cast the DataItem to teh correct type to have access to
the properties

<asp:templateco lumn ItemStyle-VerticalAlign=" Top" ItemStyle-Width="117"
ItemStyle-HorizontalAlign ="left" >
<itemtemplate >
<span ><%# ((CtpRecord)Con tainer.DataItem ).Locations.Cou nt==0?"Not set":
((CtpRecord)Con tainer.DataItem ).Locations[0].LocalName%></span>
</itemtemplate>
</asp:templatecol umn>

This is a column which require some extra processing hence I use a method
declared as protected string GetFirstDocumen tOfRecord in the code behind

<asp:templateco lumn ItemStyle-VerticalAlign=" Top" ItemStyle-Width="110"
ItemStyle-HorizontalAlign ="left" >
<itemtemplate >
<span ><%# GetFirstDocumen tOfRecord((CtpR ecord)Container .DataItem)
%></span>
</itemtemplate>
</asp:templatecol umn>
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

<dl******@gmail .com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
Hi guys, I've been reading several topics that talk about creating a
custom collection to use it as DataSource of a Datagrid.

But the fact is I have a class called Action and another class called
Profile. In my application, the user assigns several Actions to a
Profile. I thought doing this using an ArrayList of Actions and puting
that as the DataSource of the Datagrid that shows the assignments. It
works, but it shows every property Action class have.

My two questions are:
1) how can I choose the properties of Action class I want to be
bounded?
2) does it sound reasonable? I mean the ArrayList of my custom class
Action...

Thanks in advance,
Damian

Nov 17 '05 #3
Ignacio:

It's all on a web app. Maybe I didn't express myself clearly.

I want to implement some kind of interface to tell the data Grid which
properties he has to take from each object in the ArrayList.

I don't know if that's possible.

Thanks,
Dam

Nov 17 '05 #4
Ignacio:

It's all on a web app. Maybe I didn't express myself clearly.

I want to implement some kind of interface to tell the data Grid which
properties he has to take from each object in the ArrayList.

I don't know if that's possible.

Thanks,
Dam

Nov 17 '05 #5
Hi,

Ok, then the piece of code I gave you fills well , you select the
properties you want to show, you use a templacecolumn for that.

one question though, all the elements of the arraylist are of the same type
right?
just use teh code I gave you or let me know if you have any problem.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

<dl******@gmail .com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
Ignacio:

It's all on a web app. Maybe I didn't express myself clearly.

I want to implement some kind of interface to tell the data Grid which
properties he has to take from each object in the ArrayList.

I don't know if that's possible.

Thanks,
Dam

Nov 17 '05 #6

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

Similar topics

4
3898
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 it might have something to do with my page load/ postback but not really sure. Can someone please...
7
455
by: Alex Ting | last post by:
Hi Everybody, I have an issue about deleting an object from an arrayList. I've bounded a datagrid using this code where it will first run through all of the code in loadQuestions() and bind a arrayList to the datagrid. private void BindQuestions()
0
1687
by: berg | last post by:
All, I am binding an ArrayList full of custom objects to an DataGrid. The property in the custom class are all public. I define a DataGridTableStyle and set the MappingName to "ArrayList". I then add a DataGridTextBoxColumn for each of the properties in my custom class which define a MappingName --> property name in class as well as header text. When I run the form, I see correct number of rows displayed, but none of the columns...
2
7808
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 any one have any idea where Im going wrong. Thanks for any help you can give me. private void...
3
2850
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a datagrid. I am using the viewstate object to store the Arraylist items on the page on postback. My PROBLEM is that I need to redirect the user to a new aspx page and on this new page i need to be able to access the items in my arraylist. Is this...
0
357
by: dlobalzo | last post by:
Hi guys, I've been reading several topics that talk about creating a custom collection to use it as DataSource of a Datagrid. But the fact is I have a class called Action and another class called Profile. In my application, the user assigns several Actions to a Profile. I thought doing this using an ArrayList of Actions and puting that as the DataSource of the Datagrid that shows the assignments. It works, but it shows every property...
5
4856
by: Rami | last post by:
Hey, I Tried to bind a DataGrid to an ArrayList, and had 2 problems: 1. The DataGrid shows the Length property of the items instead of their text - how can I change that? 2. After binding, I add new elements to the ArrayList but the DataGrid doesnt refresh's it's view - I have to set the DataSource property of the DataGrid to Nothing and then re bind it to the ArrayList! Isnt there a "pretier" way? Thanks ahead
16
2018
by: stojilcoviz | last post by:
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.
0
1254
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 ArrayList. Both DataGrids are set to Read-Only. The user selects a row from the top DataGrid, then...
0
8365
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8788
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8563
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8646
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7390
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4200
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2776
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
2
2013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.