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

C# Custom Control Help

Hi all,
Im trying to build a custom control using Windows Control Library (C# project). I am using a textbox and a listbox for this purpose.
I want to add new items to the listbox during the design time (by exposing some property which will allow me to edit the item collection of the listbox) and restore those items on the next run. Similar to the way when we add drag a listbox or a combobox item to a normal Windows forms application and access the 'Items' property which opens up a 'String Collection Editor' to add new items. In this case the items getting added to the designer file, so the values are retained the next time the form loads.
But how do I do that in the custom control. I have tried exposing the Items property of the Listbox, which is

public ListBox.ObjectCollection Items
{
get { return this.listBox1.Items; }
set { this.listBox1.Items.AddRange(value); }
}

But this doesnt seem to wrok as it exposes an Item of type System.Object and does not allow me to add a string and retain it.

Thanks
Apr 5 '07 #1
2 2407
channaJ
67
Hi all,
Im trying to build a custom control using Windows Control Library (C# project). I am using a textbox and a listbox for this purpose.
I want to add new items to the listbox during the design time (by exposing some property which will allow me to edit the item collection of the listbox) and restore those items on the next run. Similar to the way when we add drag a listbox or a combobox item to a normal Windows forms application and access the 'Items' property which opens up a 'String Collection Editor' to add new items. In this case the items getting added to the designer file, so the values are retained the next time the form loads.
But how do I do that in the custom control. I have tried exposing the Items property of the Listbox, which is

public ListBox.ObjectCollection Items
{
get { return this.listBox1.Items; }
set { this.listBox1.Items.AddRange(value); }
}

But this doesnt seem to wrok as it exposes an Item of type System.Object and does not allow me to add a string and retain it.

Thanks
Hi SiddharthK,

Try the following code.

Expand|Select|Wrap|Line Numbers
  1. [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  2. [Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design", typeof(UITypeEditor))]
  3.         public ListBox.ObjectCollection Items
  4.         {
  5.             get
  6.             {
  7.               return this.listBox1.Items;                
  8.             }
  9.  
  10.         }
Apr 5 '07 #2
channaJ
67
Hi SiddharthK,

Try the following code.

Expand|Select|Wrap|Line Numbers
  1. [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  2. [Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design", typeof(UITypeEditor))]
  3.         public ListBox.ObjectCollection Items
  4.         {
  5.             get
  6.             {
  7.               return this.listBox1.Items;                
  8.             }
  9.  
  10.         }

if you need more info... the following link will help you.
http://msdn2.microsoft.com/en-us/library/a19191fh.aspx
Apr 5 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Tinus | last post by:
Hello all, I've create a custom control (UserControl) and have a custom Item Collection. The control is a custom calendar which is draw using the Graphics Rectangle etc. functions. It is drawn...
15
by: Tinus | last post by:
Hello all, I've created a custom control that draws a monthly schedule (using the Draw function in C#). Basically it draws 31 boxes and writes the day number in every box. This works...
21
by: One Handed Man \( OHM - Terry Burns \) | last post by:
When using a custom control. In order to check and see if values have changed one has to implement the IPostBackDataCollection interface. The values returned for the control seem to be simply a...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
19
by: Jamey Shuemaker | last post by:
I'm in the process of expanding my knowledge and use of Class Modules. I've perused MSDN and this and other sites, and I'm pretty comfortable with my understanding of Class Modules with the...
5
by: Alan Silver | last post by:
Hello, I have a products page that takes a product ID in the query string. Based on the product details (from a database), the page then loads up one of a number of custom controls, calls a...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
2
by: ahmed.maryam | last post by:
Hello Everyone, I designed a custom control that is entirely covered by a picture box. I then dragged this custom control onto a windows form application (called main) and I need to handle mouse...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.