473,320 Members | 2,020 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,320 software developers and data experts.

Passing Data From CustomControls C#

Hi Everyone,

I have a custom control on my application and I am trying to pass the data
items from the selected custom buttons back to a ListView. I'm sitting here
scratching my head thinking I should know this.

The ListViewnamed ListView1 resides on Host_Horizontal_Btn "Form1".cs and my
Custom Buttons reside on Host_Horizontal_Btn "Ctr_Horizontal_Btn.cs". What I
want is when I press my button, the item name gets added to the ListView.

Thank you all in advance.

MikeY
Mar 21 '06 #1
4 1182
On the custom control you can access the parent by:

this.Parent.Controls[...].xxx(...)

You can go as far up the chain as you want with:

this.Parent.Controls[0].Parent[1]
Here you can locate the ListView and add a new item to it.
Regards,
Lars-Inge Tønnessen
Mar 21 '06 #2
Thanks for your reply Lars-Inge. Much appreciated it. But, I've been trying
your syntax and I'm still not getting it. Manyly how to use your given line
of code. I'm going to repost/ post a new question and see what happens.
Mainly cause I cannot see any from my Form1.cs (Classes, function, etc)

Thanks again

MikeY

"Lars-Inge Tønnessen (VJ# MVP)" <http://emailme.larsinge.com> wrote in
message news:%2****************@TK2MSFTNGP09.phx.gbl...
On the custom control you can access the parent by:

this.Parent.Controls[...].xxx(...)

You can go as far up the chain as you want with:

this.Parent.Controls[0].Parent[1]
Here you can locate the ListView and add a new item to it.
Regards,
Lars-Inge Tønnessen

Mar 22 '06 #3
for future readers Delegates are the answer.

MikeY

"MikeY" <mi*******@yaho.com> wrote in message
news:7N*******************@news20.bellglobal.com.. .
Hi Everyone,

I have a custom control on my application and I am trying to pass the data
items from the selected custom buttons back to a ListView. I'm sitting
here scratching my head thinking I should know this.

The ListViewnamed ListView1 resides on Host_Horizontal_Btn "Form1".cs and
my Custom Buttons reside on Host_Horizontal_Btn "Ctr_Horizontal_Btn.cs".
What I want is when I press my button, the item name gets added to the
ListView.

Thank you all in advance.

MikeY

Mar 25 '06 #4
If I understand you correctly, the usual design is as follows.

1. Expose an event in your custom control... something like ItemAdded
(I don't know about the name... I would have to know more about your
application). Give the event arguments that carry any information you
want to transmit (like what item should be added).

2. The form that hosts the custom control then handles the event.
Whenever your custom control raises an ItemAdded event, the hosting
form handles it, extracts which thing needs to be added, constructs a
list view item, and adds it to the list view.

The idea is that the custom control doesn't know about the ListView,
and the ListView doesn't know about the custom control. The control
simply raises an event when "something interesting" happens, while the
enclosing form is the one that knows what to do about that.

This allows you to create custom controls and place them on forms
without their having to know about their environment. It's the form
that knows how things are connected.

Mar 26 '06 #5

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

Similar topics

3
by: Simon Harvey | last post by:
Hi, In my application I get lots of different sorts of information from databases. As such, a lot of information is stored in DataSets and DataTable objects. Up until now, I have been passing...
9
by: Just Me | last post by:
PARAFORMAT2 is a structure that SendMessage will return stuff in. Is the "ref" correct or since only a pointer is being passed should it be by value? Suppose I was passing data rather then...
3
by: Joe Bloggs | last post by:
Does anyone know if its possible to pass parameters or the values of Request.QueryString from a web page to a custom control class? I'm using a C# Web Application. For Example I have Web Page1...
3
by: Marc Castrechini | last post by:
First off this is a great reference for passing data between the Data Access and Business Layers:...
22
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to...
12
by: Andrew Bullock | last post by:
Hi, I have two classes, A and B, B takes an A as an argument in its constructor: A a1 = new A(); B b = new B(a1);
2
by: Rolf Welskes | last post by:
Hello, When developing Customcontrols which have other controls it seems be good practice to inherent from CompositeControl. But other as at WebControl I am not able to set the tag of the...
7
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
3
by: DaTurk | last post by:
If I call this method, and pass it a byte by ref, and initialize another byte array, set the original equal to it, and then null the reference, why is the original byte array not null as well? I...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.