By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,458 Members | 1,422 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,458 IT Pros & Developers. It's quick & easy.

classes

P: n/a
hi all,

I have a usercontrol with a checked listbox

this usercontrol is placed on a form1

is there a way to get the checked items of the checkedlisbox in the
usercontrol with a command from form1?

i beleave i have to do this with "get" and "set in a class

i've never worked with classes before

the way to get the items from the listbox is the code below.

thanks Maarten.

public void getchecked()

{

for (int x = 0; x <= (lstChannels.Items.Count-1); x++)

{

if (lstChannels.GetItemChecked(x))

{

}
else

{

}

}
Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Maarten wrote:
hi all,

I have a usercontrol with a checked listbox

this usercontrol is placed on a form1

is there a way to get the checked items of the checkedlisbox in the
usercontrol with a command from form1?

i beleave i have to do this with "get" and "set in a class

i've never worked with classes before

the way to get the items from the listbox is the code below.

thanks Maarten.

public void getchecked()

{

for (int x = 0; x <= (lstChannels.Items.Count-1); x++)

Note: a usual way to write the mid-part is:
x < lstChannels.Items.Count
("<" instead of "<=" and no "-1")
{

if (lstChannels.GetItemChecked(x))
do you mean "lstChannels.Items[x].Checked" ?

{

}
else

{

}

}


You want to access values from the UserControl from within the
containing aspx page (if I understand correctly).
Usually (meaning: the way I write them :-) ) an ascx is self-contained:
all processing is done internally, a surrounding control or page
does not need to know anything about it.

When you add a textbox to a page (or ascx), you get a declaration
in the codebehind. This is not done automatically for ascx'es,
so you have to add it yourself.
After that you can access any properties within that control,
IF the access modifiers are set correctly ("public").

--
Hans Kesting
Nov 16 '05 #2

P: n/a
Hi Hans,

thanks for the reply

i have some public functions in that usercontrole, and i have been able to
call them from the main form1
with:
usercontrol1.getchecked();

but this isn't realy the problem.

i was wondering if i can put this getcheched void in a class, so i can
rertieve the data (in this case the checked itmes) of that class with
something like "get" and "set" (ive seen some exaples with this code).

i'm asking this question rather because i'm trying to understand classes
more than actualy
let let this whole thing work.

i've been looking for a long time on the net trying to understand, but i
just wont get it.

Can you please post a simple example.

kind regards Maarten
"Hans Kesting" <ne***********@spamgourmet.com> schreef in bericht
news:%2******************@TK2MSFTNGP15.phx.gbl...
Maarten wrote:
hi all,

I have a usercontrol with a checked listbox

this usercontrol is placed on a form1

is there a way to get the checked items of the checkedlisbox in the
usercontrol with a command from form1?

i beleave i have to do this with "get" and "set in a class

i've never worked with classes before

the way to get the items from the listbox is the code below.

thanks Maarten.

public void getchecked()

{

for (int x = 0; x <= (lstChannels.Items.Count-1); x++)


Note: a usual way to write the mid-part is:
x < lstChannels.Items.Count
("<" instead of "<=" and no "-1")
{

if (lstChannels.GetItemChecked(x))


do you mean "lstChannels.Items[x].Checked" ?

{

}
else

{

}

}


You want to access values from the UserControl from within the containing
aspx page (if I understand correctly).
Usually (meaning: the way I write them :-) ) an ascx is self-contained:
all processing is done internally, a surrounding control or page
does not need to know anything about it.

When you add a textbox to a page (or ascx), you get a declaration
in the codebehind. This is not done automatically for ascx'es,
so you have to add it yourself.
After that you can access any properties within that control,
IF the access modifiers are set correctly ("public").

--
Hans Kesting

Nov 16 '05 #3

P: n/a
I think what you want is to expose the Items property of the listbox. Inside
your usercontrol class you could do something like
public virtual ListItemCollection Items
{
get{ return listBox.Items; }
}
(I am not sure about the type of the items collection?)

If you want them to be editable in the designer, you could attributes like

[Description("Gets the collection of items displayed in the list."),
DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content),
Editor("System.Windows.Forms.Design.StringCollecti onEditor,
System.Design", typeof(UITypeEditor))]

If you don't want them to be seen in the designer, you could set
[Browsable(false)]

Hope this helps,
-Rachel

"Maarten" <gu******@hotmail.com> wrote in message
news:42***********************@news.skynet.be...
hi all,

I have a usercontrol with a checked listbox

this usercontrol is placed on a form1

is there a way to get the checked items of the checkedlisbox in the
usercontrol with a command from form1?

i beleave i have to do this with "get" and "set in a class

i've never worked with classes before

the way to get the items from the listbox is the code below.

thanks Maarten.

public void getchecked()

{

for (int x = 0; x <= (lstChannels.Items.Count-1); x++)

{

if (lstChannels.GetItemChecked(x))

{

}
else

{

}

}

Nov 16 '05 #4

P: n/a
BTW...
You only need (can use) the "get" in this property because the collection
itself is readonly. However, you can add to the collection by using
Items.Add(), so you have all the functionality with only a get on the items.

"Rachel Suddeth" <ra****@bldhound.com> wrote in message
news:OV**************@TK2MSFTNGP12.phx.gbl...
I think what you want is to expose the Items property of the listbox. Inside your usercontrol class you could do something like
public virtual ListItemCollection Items
{
get{ return listBox.Items; }
}
(I am not sure about the type of the items collection?)

If you want them to be editable in the designer, you could attributes like

[Description("Gets the collection of items displayed in the list."),
DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content), Editor("System.Windows.Forms.Design.StringCollecti onEditor,
System.Design", typeof(UITypeEditor))]

If you don't want them to be seen in the designer, you could set
[Browsable(false)]

Hope this helps,
-Rachel

"Maarten" <gu******@hotmail.com> wrote in message
news:42***********************@news.skynet.be...
hi all,

I have a usercontrol with a checked listbox

this usercontrol is placed on a form1

is there a way to get the checked items of the checkedlisbox in the
usercontrol with a command from form1?

i beleave i have to do this with "get" and "set in a class

i've never worked with classes before

the way to get the items from the listbox is the code below.

thanks Maarten.

public void getchecked()

{

for (int x = 0; x <= (lstChannels.Items.Count-1); x++)

{

if (lstChannels.GetItemChecked(x))

{

}
else

{

}

}


Nov 16 '05 #5

P: n/a
Thans for answering my question

I still didn't fugured it out yet, but thanks anyway

"Rachel Suddeth" <ra****@bldhound.com> schreef in bericht
news:%2****************@TK2MSFTNGP14.phx.gbl...
BTW...
You only need (can use) the "get" in this property because the collection
itself is readonly. However, you can add to the collection by using
Items.Add(), so you have all the functionality with only a get on the
items.

"Rachel Suddeth" <ra****@bldhound.com> wrote in message
news:OV**************@TK2MSFTNGP12.phx.gbl...
I think what you want is to expose the Items property of the listbox.

Inside
your usercontrol class you could do something like
public virtual ListItemCollection Items
{
get{ return listBox.Items; }
}
(I am not sure about the type of the items collection?)

If you want them to be editable in the designer, you could attributes
like

[Description("Gets the collection of items displayed in the list."),

DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content),
Editor("System.Windows.Forms.Design.StringCollecti onEditor,
System.Design", typeof(UITypeEditor))]

If you don't want them to be seen in the designer, you could set
[Browsable(false)]

Hope this helps,
-Rachel

"Maarten" <gu******@hotmail.com> wrote in message
news:42***********************@news.skynet.be...
> hi all,
>
> I have a usercontrol with a checked listbox
>
> this usercontrol is placed on a form1
>
> is there a way to get the checked items of the checkedlisbox in the
> usercontrol with a command from form1?
>
> i beleave i have to do this with "get" and "set in a class
>
> i've never worked with classes before
>
> the way to get the items from the listbox is the code below.
>
> thanks Maarten.
>
> public void getchecked()
>
> {
>
> for (int x = 0; x <= (lstChannels.Items.Count-1); x++)
>
> {
>
> if (lstChannels.GetItemChecked(x))
>
> {
>
> }
>
>
> else
>
> {
>
> }
>
> }
>
>



Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.