Re: I've got a strange bug with Listbox.DataSource...
From: Justin Rogers (Justin_at_games4dotnet.com)
Date: 11/06/04
- Next message: David Anton: "re:c# in .Net code examples?"
- Previous message: Justin Rogers: "Re: No Check Mnemonics in C#???!!!"
- In reply to: Zoury: "I've got a strange bug with Listbox.DataSource..."
- Messages sorted by: [ date ] [ thread ]
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 > >
- Next message: David Anton: "re:c# in .Net code examples?"
- Previous message: Justin Rogers: "Re: No Check Mnemonics in C#???!!!"
- In reply to: Zoury: "I've got a strange bug with Listbox.DataSource..."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|