473,779 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I've got a strange bug with Listbox.DataSou rce...

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.Seri alization.XmlTy peAttribute(Nam espace="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.DataS ource = records;
lbRecords.Displ ayMember = "TableName" ;
lbRecords.Value Member = "ID";
}
//***

in this case I got an ArgumentExcepti on 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.Displ ayMember = "TableName" ;
lbRecords.Value Member = "ID";
lbRecords.DataS ource = 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 1939
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(R ecord record) { this.record = record; }
public string TableName { get { return this.record.Tab leName; } }
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******** ******@TK2MSFTN GP10.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.Seri alization.XmlTy peAttribute(Nam espace="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.DataS ource = records;
lbRecords.Displ ayMember = "TableName" ;
lbRecords.Value Member = "ID";
}
//***

in this case I got an ArgumentExcepti on 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.Displ ayMember = "TableName" ;
lbRecords.Value Member = "ID";
lbRecords.DataS ource = 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
5910
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 ArrayList only has one element in it everything works ok. But as soon as I have more than one element, I get the following exception when the control loads up: "Cannot modify the Items collection when the DataSource property is set.". Anybody...
2
2119
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; using System.Collections; using System.Collections.Specialized; using System.ComponentModel; using System.Data; using System.Drawing;
0
4624
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 from the ArrayList and re-attach the ArrayList to the ListBox the program hangs for about 3-5 seconds then keep running normal. I'm following the examples from the MSDN and dont see anything abnormal. This is a sample of the code I'm using: 1...
2
3426
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 graphically the change: e.g. if I remove an element from the ArrayList object, then that element should not be no more displayed in the list box. Actually i'm using this code below:
6
2881
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 a denormalized mirror of the database, but I'm not having much luck getting the selection logic down (I haven't found a 'hook' where I can access the listbox object as an object to set the listitem's selected property before it gets rendered).. ...
13
2309
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 the selected value from the left listbox. When you select any member from the left listbox and click on the button to move it to the right listbox, everything works fine. If you select the LAST member in the left listbox, and click on the button...
11
8556
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 the array list again to refresh. Click on an item in the list, and an Indexing error comes up. (in non-user code, it is trying to get an element from the array that is greater than the number of items in the array.) To reproduce:
7
4539
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 ASP.Net stuff when I need a Windows Form control. I've seen dual listbox populators in countless Windows applications, and have seen them run very fast, so I figured this would be extremely popular. Here's how it should work:
4
1585
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, i.e. MyDataSource.Add("XXX")/MyDatasource.Remove("YYY") I would expect that this XXX is shown in a Listbox/YYY deleted from a listbox, but it is not the case. How do force a ListBox to reread DataSource
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10137
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7483
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.