Click here to Skip to main content
15,913,055 members
Home / Discussions / C#
   

C#

 
AnswerRe: DAL/BLL Best Practices [modified] Pin
eggsovereasy2-Aug-06 10:03
eggsovereasy2-Aug-06 10:03 
GeneralRe: DAL/BLL Best Practices Pin
econner2-Aug-06 10:12
econner2-Aug-06 10:12 
GeneralRe: DAL/BLL Best Practices Pin
eggsovereasy2-Aug-06 10:35
eggsovereasy2-Aug-06 10:35 
QuestionHow to assign text control's value to a numeric variable? Pin
Amol Ravatale2-Aug-06 7:54
Amol Ravatale2-Aug-06 7:54 
AnswerRe: How to assign text control's value to a numeric variable? Pin
Stefan Troschuetz2-Aug-06 8:34
Stefan Troschuetz2-Aug-06 8:34 
AnswerRe: How to assign text control's value to a numeric variable? Pin
engsrini2-Aug-06 8:35
engsrini2-Aug-06 8:35 
AnswerRe: How to assign text control's value to a numeric variable? Pin
BlackDice2-Aug-06 8:38
BlackDice2-Aug-06 8:38 
QuestionStrange Behavior Pin
Mehdi Mousavi2-Aug-06 5:43
Mehdi Mousavi2-Aug-06 5:43 
Hi folks,
I've create a UserControl that could return a property of type
AddressCollection - a collection of Address classes (derived from
CollectionBase). I've also created an AddressTypeConverter that's being
derived from TypeConverter as well as an AddressCollectionEditor that's
being derived from CollectionEditor as follows:


////////////////////////////////////////AddressCollectionEditor<br />
    public class AddressCollectionEditor : CollectionEditor<br />
    {<br />
        public AddressCollectionEditor(Type type)<br />
            : base(type){}<br />
<br />
        protected override bool CanSelectMultipleInstances(){return<br />
false;}<br />
<br />
        protected override Type CreateCollectionItemType(){return<br />
typeof(Address);}<br />
    }<br />
<br />
////////////////////////////////////////AddressTypeConverter<br />
[Serializable]<br />
    public class AddressTypeConverter : TypeConverter<br />
    {<br />
        public override bool CanConvertTo(ITypeDescriptorContext<br />
context, Type destinationType)<br />
        {<br />
            if (destinationType == typeof(InstanceDescriptor))<br />
                return true;<br />
<br />
            return base.CanConvertTo(context, destinationType);<br />
        }<br />
<br />
        public override object ConvertTo(ITypeDescriptorContext<br />
context, System.Globalization.CultureInfo culture, object value, Type<br />
destinationType)<br />
        {<br />
            if (destinationType == typeof(InstanceDescriptor))<br />
            {<br />
                Address addr = value as Address;<br />
                if (addr == null)<br />
                    return new<br />
InstanceDescriptor(typeof(Address).GetConstructor(System.Type.EmptyTypes),<br />
null);<br />
<br />
                return new<br />
InstanceDescriptor(typeof(Address).GetConstructor(new Type[] {<br />
typeof(string), typeof(string), typeof(string), typeof(string),<br />
typeof(string), typeof(string), typeof(string) }),<br />
<br />
     new string[] { addr.Type, addr.Street1, addr.Street2, addr.City,<br />
addr.StateProvince, addr.ZipPostalCode, addr.CountryRegion });<br />
            }<br />
<br />
            return base.ConvertTo(context, culture, value,<br />
destinationType);<br />
        }<br />
    }<br />
<br />
////////////////////////////////////////AddressCtrl<br />
public partial class AddressCtrl : UserControl<br />
{<br />
  //removed for clarity....<br />
<br />
        [Category("Misc"), Description("Get a collection of<br />
addresses.")]<br />
        [Editor(typeof(AddressCollectionEditor), typeof(UITypeEditor))]<br />
<br />
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]<br />
        public AddressCollection Addresses<br />
        {<br />
            get { return m_coll; }<br />
        }<br />
<br />
}<br />
<br />
////////////////////////////////////////Address<br />
    [Serializable]<br />
    [TypeConverter(typeof(AddressTypeConverter))]<br />
    public class Address : ICloneable<br />
    {<br />
         //removed for clarity....<br />
<br />
        private string m_strType;<br />
        private string m_strStreet1, m_strStreet2;<br />
        private string m_strCity, m_strStateProvince;<br />
        private string m_strZipPostalCode, m_strCountryRegion;<br />
<br />
        public Address()<br />
            : this("Unknown", string.Empty, string.Empty, string.Empty,<br />
string.Empty, string.Empty, string.Empty)<br />
        {<br />
        }<br />
<br />
        public Address(string strType, string strStreet1, string<br />
strStreet2, string strCity, string strStateProvince, string<br />
strZipPostalCode, string strCountryRegion)<br />
        {<br />
        }<br />
<br />
         //All the member variables are exposed to the outer world<br />
through some<br />
         //accessors (get/set)....<br />
    }


Everything works fine and the following code is generated in the
InitializeComponent:

<br />
this.addressCtrl1.Addresses.AddRange(new Address[] {<br />
            new Address("Business", "", "", "", "", "", ""),<br />
            new Address("Home", "", "", "", "", "", ""),<br />
            new Address("Shipping", "", "", "", "", "", ""),<br />
            new Address("Billing", "", "", "", "", "", "")});<br />


However, when I try to remove a given item, the InitializeComponent
looks like this:

<br />
this.addressCtrl1.Addresses.AddRange(new Address[] {<br />
            ((Address)(new Address())),<br />
            ((Address)(new Address())),<br />
            ((Address)(new Address())),<br />
            ((Address)(new Address()))});<br />


Would you please let me know what I'm doing wrong?

Thank you for your time,
Mehdi

Mehdi Mousavi - Software Architect [ http://mehdi.biz ]

QuestionScreenshots Pin
Kovu172-Aug-06 5:08
Kovu172-Aug-06 5:08 
AnswerRe: Screenshots Pin
Judah Gabriel Himango2-Aug-06 5:24
sponsorJudah Gabriel Himango2-Aug-06 5:24 
GeneralRe: Screenshots Pin
Kovu172-Aug-06 23:22
Kovu172-Aug-06 23:22 
GeneralRe: Screenshots Pin
Judah Gabriel Himango3-Aug-06 4:21
sponsorJudah Gabriel Himango3-Aug-06 4:21 
Questionhow to create a color eyedroppper? Pin
relsirc2-Aug-06 4:36
relsirc2-Aug-06 4:36 
AnswerRe: how to create a color eyedroppper? Pin
Ennis Ray Lynch, Jr.2-Aug-06 4:42
Ennis Ray Lynch, Jr.2-Aug-06 4:42 
Questionhow to remove duplicate characters from a text file [modified] Pin
vp152-Aug-06 4:35
vp152-Aug-06 4:35 
AnswerRe: how to remove duplicate characters from a text file Pin
Ennis Ray Lynch, Jr.2-Aug-06 4:44
Ennis Ray Lynch, Jr.2-Aug-06 4:44 
QuestionClass doesn't support Automation [modified] Pin
Lupson2-Aug-06 4:21
Lupson2-Aug-06 4:21 
QuestionHow to set zoom in WebBrowser? Pin
Dima Filipiuk2-Aug-06 3:46
Dima Filipiuk2-Aug-06 3:46 
QuestionCompare values with List Pin
abnorm2-Aug-06 3:30
abnorm2-Aug-06 3:30 
AnswerRe: Compare values with List [modified] Pin
Wjousts2-Aug-06 3:48
Wjousts2-Aug-06 3:48 
AnswerRe: Compare values with List Pin
Ingo2-Aug-06 3:48
Ingo2-Aug-06 3:48 
GeneralRe: Compare values with List Pin
Wjousts2-Aug-06 4:01
Wjousts2-Aug-06 4:01 
GeneralRe: Compare values with List Pin
abnorm2-Aug-06 4:13
abnorm2-Aug-06 4:13 
GeneralRe: Compare values with List Pin
Wjousts3-Aug-06 3:23
Wjousts3-Aug-06 3:23 
GeneralRe: Compare values with List Pin
Ingo2-Aug-06 4:19
Ingo2-Aug-06 4:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.