Re: I've got a strange bug with Listbox.DataSource...

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Justin Rogers (Justin_at_games4dotnet.com)
Date: 11/06/04


Date: Fri, 5 Nov 2004 16:51:31 -0800

Yeah, this kinda sucks. What you need is an adapter that surfaces your two
fields as properties. I generally call these by a rather nasty name each time
I have to generate them by hand ;-)

class or struct RecordWrapper {
    private Record record;
    public RecordWrapper(Record record) { this.record = record; }
    public string TableName { get { return this.record.TableName; } }
    public int Id = { get { return this.record.Id; } }
}

-- 
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
"Zoury" <yanick_lefebvre@hotmail.com> wrote in message 
news:u51QiL4wEHA.3260@TK2MSFTNGP10.phx.gbl...
> Hi there! :O)
>
> I have a WebService that contains the following struct definition. this
> struct is defined right after the WebService class, ie :
> //***
> namespace mynamespace
> {
>    public class MyWebService : WebService {// code here..}
>    public struct Record
>    {
>        // fields
>        private Int32 _id;
>        private string _tableName;
>
>        // constructors
>        public Record(Int32 id, string tableName)
>        {
>            _id = id;
>            _tableName = tableName;
>        }
>
>        // public properties
>        public string TableName
>        {
>            get {return _tableName;}
>            set {_tableName = value;}
>        }
>        public Int32 ID
>        {
>            get {return _id;}
>            set {_id = value;}
>        }
> }
> //***
>
> this is the class definition of the struct in reference.cs :
> //***
>    /// <remarks/>
>
> [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
>    public class Record {
>
>        /// <remarks/>
>        public string TableName;
>
>        /// <remarks/>
>        public int ID;
>    }
> //***
>
>
>
>
> In a window application i must load a listbox from a Record[] type,
> so i did something like this :
> //***
> private void FillList(Record[] records)
> {
>        // lbRecords is a ListBox
>        lbRecords.DataSource = records;
>        lbRecords.DisplayMember = "TableName";
>        lbRecords.ValueMember = "ID";
> }
> //***
>
> in this case I got an ArgumentException on the last line of code.
> Additionnal information : Could not bind to the new display
> member.
>
> PLUS, right after the exception occured, i click [Break], then over the
> mouse cursor over DisplayMember and ValueMember to see what there are set
> to. Strangely, DisplayMember contains "ID" and ValueMember contains ""...
>
>
> so i decided to try something else... :
> //***
> private void FillList(Record[] records)
> {
>        // lbRecords is a ListBox
>        lbRecords.DisplayMember = "TableName";
>        lbRecords.ValueMember = "ID";
>        lbRecords.DataSource = records;
> }
> //***
>
> This way, no exceptions are thrown.. but, once the last line of code
> executes, the DisplayMember value gets replaced by "" and the only thing
> appearing in the listbox is the type information of Record which is probably
> caused by the fact the listbox calls .ToString() on each members of the
> Array.
>
>
>
> Can anybody see what is wrong with this code ?!
> I mean, "TableName" is properly spelled.... is there a problem with using a
> struct definition from a WebService ?
>
> Thanks a lot for reading me!
>
> -- 
> Best Regards
> Yanick Lefebvre
>
> 


Relevant Pages

  • Ive got a strange bug with Listbox.DataSource...
    ... I have a WebService that contains the following struct definition. ... DisplayMember contains "ID" and ValueMember contains ""... ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: "data hiding" prototype code
    ... struct definition in the header. ... Secondly, static variables at file ...
    (comp.lang.c)
  • Re: [PATCH 13/15] perf_counter: provide generic callchain bits
    ... struct definition is not visible to userspace (it's in the #ifdef KERNEL ... header in the userspace bits. ... chain with 0ULL. ... This chain however will not change the struct, ...
    (Linux-Kernel)
  • Re: null function pointer?
    ... >> The type is incomplete until the closing brace of the list ... > point of the code in your example in all declarations `struct foo' ... > declarations have the same scope and use the same struct tag). ... > type before and after the struct definition, ...
    (comp.lang.c)
  • Re: "data hiding" prototype code
    ... struct definition in the header. ... typedef struct foo_st foo_t; ...
    (comp.lang.c)