Passing Data From Cust Control To main Form [C# Win]

M

MikeY

Hi everyone,

I'm having problems, or should I say still having problems with trying to
pass data from my custom buttons in my custom controls to my main form
listview box. Still scratching my head and had a sleepless night trying to
figure this one out. So hopefully someone can help.

I have a user control named Ctr_Horizontal_Btn.cs (houses my custom buttons)
namespace = HOST_Horizontal_Btn. A public class named =
Ctr_Horizontal_Btn.cs. This resides on my Windows main form named =
Form1.cs. Namespace is also Ctr_Horizontal_Btn.cs. There is a ListView Box
named = listView1 on my Form1. What I am trying to do is when I click my
custom button. I want to display in the listView1 with the text of the
button ie: "Hello World".

Unfortunitly I don't seem to have access to the Form1.cs classes, funtions,
etc. I posted yesterday and recieved a reply of :
"this.Parent.Controls[0].Parent[1]" but I am unsure of how to put data into
my listview with this syntax. I can read my listview with it, just can't put
data into my listView1.

Any and all help is appreciated

MikeY
 
T

Tom Porterfield

MikeY said:
Hi everyone,

I'm having problems, or should I say still having problems with trying to
pass data from my custom buttons in my custom controls to my main form
listview box. Still scratching my head and had a sleepless night trying to
figure this one out. So hopefully someone can help.

I have a user control named Ctr_Horizontal_Btn.cs (houses my custom
buttons) namespace = HOST_Horizontal_Btn. A public class named =
Ctr_Horizontal_Btn.cs. This resides on my Windows main form named =
Form1.cs. Namespace is also Ctr_Horizontal_Btn.cs. There is a ListView Box
named = listView1 on my Form1. What I am trying to do is when I click my
custom button. I want to display in the listView1 with the text of the
button ie: "Hello World".

Unfortunitly I don't seem to have access to the Form1.cs classes,
funtions, etc. I posted yesterday and recieved a reply of :
"this.Parent.Controls[0].Parent[1]" but I am unsure of how to put data
into my listview with this syntax. I can read my listview with it, just
can't put data into my listView1.

You shouldn't do it this way. If the requirement is that the button must
put the text into the listview, then make the listview part of the custom
control. If you want to leave the listview separate from the custom button
control, then have the custom button control raise an event when the button
is clicked, passing the text of the button. The form hosting the controls
would listen for that event and when fired, take the text and put it into
the listview.
 
M

MikeY

Txs Tom for your reply. I'll give it a go.

MikeY

Tom Porterfield said:
MikeY said:
Hi everyone,

I'm having problems, or should I say still having problems with trying to
pass data from my custom buttons in my custom controls to my main form
listview box. Still scratching my head and had a sleepless night trying
to
figure this one out. So hopefully someone can help.

I have a user control named Ctr_Horizontal_Btn.cs (houses my custom
buttons) namespace = HOST_Horizontal_Btn. A public class named =
Ctr_Horizontal_Btn.cs. This resides on my Windows main form named =
Form1.cs. Namespace is also Ctr_Horizontal_Btn.cs. There is a ListView
Box
named = listView1 on my Form1. What I am trying to do is when I click my
custom button. I want to display in the listView1 with the text of the
button ie: "Hello World".

Unfortunitly I don't seem to have access to the Form1.cs classes,
funtions, etc. I posted yesterday and recieved a reply of :
"this.Parent.Controls[0].Parent[1]" but I am unsure of how to put data
into my listview with this syntax. I can read my listview with it, just
can't put data into my listView1.

You shouldn't do it this way. If the requirement is that the button must
put the text into the listview, then make the listview part of the custom
control. If you want to leave the listview separate from the custom
button control, then have the custom button control raise an event when
the button is clicked, passing the text of the button. The form hosting
the controls would listen for that event and when fired, take the text and
put it into the listview.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top