How to see the [Items] property of the Listbox that is inside UserControl
-
I made a custom UserControl and in it i put a Listbox. In Form1, in the properties of the UserControl I want to see the [Items] property of the Listbox that is inside UserControl. How to do that? thanks.
Create the property yourself, and delegate the get/set methods to the property on the listbox.
Regards, Rob Philpott.
-
Create the property yourself, and delegate the get/set methods to the property on the listbox.
Regards, Rob Philpott.
-
Ok something like (in your user control):
public ListBox.Collection Items
{
get { return listbox1.Items; }
set { listbox1.Items = value; }
}... (edit) although you probably don't want the setter thinking about it..
Regards, Rob Philpott.
-
Ok something like (in your user control):
public ListBox.Collection Items
{
get { return listbox1.Items; }
set { listbox1.Items = value; }
}... (edit) although you probably don't want the setter thinking about it..
Regards, Rob Philpott.
ListBox.Collection does not exist!
I found this but with a little problem:public ListBox.ObjectCollection Items
{
get { return listBox1.Items; }
set { listBox1.Items = value; }//Error--System.Windows.Forms.ListBox.Items' cannot be assigned to -- it is read only
} -
ListBox.Collection does not exist!
I found this but with a little problem:public ListBox.ObjectCollection Items
{
get { return listBox1.Items; }
set { listBox1.Items = value; }//Error--System.Windows.Forms.ListBox.Items' cannot be assigned to -- it is read only
}yeah, I edited the original - you can't set it, so just forget the second line and you should be there.
Regards, Rob Philpott.
-
yeah, I edited the original - you can't set it, so just forget the second line and you should be there.
Regards, Rob Philpott.
I figure it out and it works:
public ListBox.ObjectCollection Items
{
get { return listBox1.Items; }
}But when i open Items property from the Property panel, a window appear (Object Collection Editor) and it let me add and remove items but with no capability of editing those items... how to solve that? I observe that when i open Items property for the actual listBox1 another window appear (String Collection Editor). How to add the (String...) instead of (Object...)? The ListBox have only these classes available: ___(and no String Collection)
//ControlAccessibleObject //ControlCollection //IntegerCollection //ObjectCollection //SelectedIndexCollection //SelectedObjectCollection
modified on Tuesday, June 21, 2011 8:59 AM
-
yeah, I edited the original - you can't set it, so just forget the second line and you should be there.
Regards, Rob Philpott.
in Form1 I wrote this and is working all right: (BUT...I want to be able to add items not only programmatic, but from properties panel too.)
private void Form1_Load(object sender, EventArgs e)
{
StreamReader sr = new StreamReader(path + "\\Sessions.txt");
RichTextBox rtb = new RichTextBox();
rtb.Text = sr.ReadToEnd();for (int i = 0; i < rtb.Lines.Length-1; i++) { session1.listBox1.Items.Add(rtb.Lines\[i\]);//session1 is my UserControl //session1.aItems.Add(rtb.Lines\[i\]); // this is working too } sr.Close(); }
-
in Form1 I wrote this and is working all right: (BUT...I want to be able to add items not only programmatic, but from properties panel too.)
private void Form1_Load(object sender, EventArgs e)
{
StreamReader sr = new StreamReader(path + "\\Sessions.txt");
RichTextBox rtb = new RichTextBox();
rtb.Text = sr.ReadToEnd();for (int i = 0; i < rtb.Lines.Length-1; i++) { session1.listBox1.Items.Add(rtb.Lines\[i\]);//session1 is my UserControl //session1.aItems.Add(rtb.Lines\[i\]); // this is working too } sr.Close(); }
-
you don't need the richttextbox, you should be able to iterate through the lines of the StreamReader (ReadLine method)
V.
-
"you don't need the richtextbox""
And how do I take the lines from file (here:[for (int i = 0; i < rtb.Lines.Length-1; i++)]?Just take a look at the documentation of StreamReader ; there should be a ReadLine() method. Well, here's the link : StreamReader.ReadLine()
-
Just take a look at the documentation of StreamReader ; there should be a ReadLine() method. Well, here's the link : StreamReader.ReadLine()
-
Sorry, I don't know how to customize the collection editor for your needs. This should be possible as there are some attributes that you can add to your USerControl that will let you customize their behavior. Here's another link that could help you get the point Hope this points you in the right direction.
-
I figure it out and it works:
public ListBox.ObjectCollection Items
{
get { return listBox1.Items; }
}But when i open Items property from the Property panel, a window appear (Object Collection Editor) and it let me add and remove items but with no capability of editing those items... how to solve that? I observe that when i open Items property for the actual listBox1 another window appear (String Collection Editor). How to add the (String...) instead of (Object...)? The ListBox have only these classes available: ___(and no String Collection)
//ControlAccessibleObject //ControlCollection //IntegerCollection //ObjectCollection //SelectedIndexCollection //SelectedObjectCollection
modified on Tuesday, June 21, 2011 8:59 AM