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

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

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(Namespac e="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
Nov 16 '05 #1
1 1900
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" <ya*************@hotmail.com> wrote in message
news:u5**************@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(Namespac e="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

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jason | last post by:
Here is an odd issue. I am trying to shed some light on why this is causing a problem. I have an ArrayList. I am binding it to a ListBox control with has its Sort property set to True. If the...
2
by: mathieu cupryk | last post by:
I have problems with listboxes in the webform2.cs, the textboxes are working well when I do a click on next. I am missing something. It works with the textboxes. Here is the file: using System;...
0
by: Jesse Martinez | last post by:
My problem occurs when I use an ArrayList as a ListBox.DataSource. When the ArrayList attached to the Listbox is not empty the Listbox behave normal without problem, but if I remove all items...
2
by: Luca | last post by:
Hello, I'm using a windows form in which there is a standard ListBox control. I want to add/remove objects from the ArrayList associated to the ListBox, and I want the ListBox immediately shows...
6
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
13
by: Larry Woods | last post by:
I am creating a "from-to" set of listboxes where the "left" listbox had a list of values and I want to be able to select these values, 1 at a time, and move them into a "right" listbox, removing...
11
by: Zorpiedoman | last post by:
The problem is this: I have a list box. I set an array list as the datasource. I remove an item from the array list. I set the listbox datasource to nothing. I set the listbox datasource to...
7
by: Dave | last post by:
Hi all, After unsuccessfully trying to make my own dual listbox control out of arraylists, I decided to look for a 3rd party control. I've looked for over a week now and can't find anything but...
4
by: Boni | last post by:
Dear all, I have a very simple question. I have a listbox with datasource, where DataSource is an arraylist. I.e. MyListbox.DataSource=MyDataSource. Now I add/remove something to DataSource,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.