Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / July 2004

Tip: Looking for answers? Try searching our database.

displaying data in list box

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Derrick - 23 Jun 2004 23:45 GMT
Hi

I have a form that has a list box bound to a Data view.

When I add a record to the data table in run time, it is displayed in the
list box as System.Data.DatarowView.  When the app is saved and reloaded,
the data appears properly.  Any ideas on how to work around?

Code Snippet to add the row to the data table
<Snip>
DataSetInfo.DetailsRow dr = this.dataSetInfo.Details.NewDetailsRow();
... code to fill the fields
this.dataSetInfo.Details.AddDetailsRow(dr);
</Snip>

Derrick
"Ying-Shen Yu[MSFT]" - 24 Jun 2004 07:49 GMT
Hi Derrick,

You may check the value of DataSource and DisplayMember property of the
listbox, when displaying "System.Data.DataRowView",
probably this issue is caused by you set DataSource to a certain DataTable
however the DisplayMember property was not set to a data column. In this
scenario, Listbox usesToString() method to convert the object into string
before adding it.

Please feel free to let me know if your problem is not the case, Thanks!
Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
Derrick - 24 Jun 2004 20:08 GMT
Thanks for the response.

the DataSource is set to the dataView - and DisplayMember is set to the
correct field, so that is not the problem in this case.

Derrick

> Hi Derrick,
>
[quoted text clipped - 15 lines]
> This mail should not be replied directly, please remove the word "online"
> before sending mail.
"Ying-Shen Yu[MSFT]" - 25 Jun 2004 03:00 GMT
Hi Derrick,

If DataSource and DisplayMember is set correctly,  
this issue needs some further investigation, could you seperate this issue
into a small project and send me to let me take a look?

Also , Here is a small code snippet I tried without problem on my side, I
pasted it below, maybe you can tell me the difference between my test and
your reall scenario.
//I generated a strong-type dataset from Customer table,
//there are two fields in it, "CustID"(string), and "Name"(string)
//I only put a listbox and a button on the Form.
private void button1_Click(object sender, system.EventArgs e)
{
    DataView dv = new DataView( dataSet11.Customers );
    listBox1.DataSource = dv;
    listBox1.DisplayMember = "CustID";
    DataSet1.CustomersRow dr = dataSet11.Customers.NewCustomersRow();
    dr["CustID"] = "1234";
    dr["Name"] = "aaaa";
    dataSet11.Customers.AddCustomersRow( dr );
}

Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
Derrick - 25 Jun 2004 05:11 GMT
I will post it tomorrow AM

thx for the help.

Derrick

> Hi Derrick,
>
[quoted text clipped - 30 lines]
> This mail should not be replied directly, please remove the word "online"
> before sending mail.
Derrick - 03 Jul 2004 00:01 GMT
Sorry for the delay in following up to your response - I had trouble
creating the objects in a simple app that would replicate the error.
Until I get that finished, here is the code I am using to put data into the
dataview

private void buttonAdd_Click(object sender, System.EventArgs e)
{
DataSetGolfPool.PicksRow dr = this.DataSetGolfPool.Picks.NewPicksRow();
dr.poolie_ID=Convert.ToInt32(this.ComboBoxPoolies.SelectedValue);
dr.tournament_ID=Convert.ToInt32(this.ComboBoxTournaments.SelectedValue);
dr.golfer_ID=Convert.ToInt32(this.ListBoxGolfers.SelectedValue);
dr.fullName=Convert.ToString(this.ListBoxGolfers.SelectedItem);
this.DataSetGolfPool.Picks.AddPicksRow(dr);
}

The row filter I am using:

this.DataViewPicks.RowFilter= String.Concat( "poolie_id=",
this.ComboBoxPoolies.SelectedValue, " AND tournament_id=",
this.ComboBoxTournaments.SelectedValue);

The ListBox is bound with the following properties:

this.ListBoxPicks.DataSource = this.DataViewPicks;
this.ListBoxPicks.DisplayMember = "fullName";
this.ListBoxPicks.Location = new System.Drawing.Point(616, 80);
this.ListBoxPicks.Name = "ListBoxPicks";
this.ListBoxPicks.Size = new System.Drawing.Size(160, 108);
this.ListBoxPicks.TabIndex = 4;
this.ListBoxPicks.ValueMember = "id";

//

// SqlDataAdapterPicks

//
this.SqlDataAdapterPicks.DeleteCommand = this.sqlDeleteCommand2;
this.SqlDataAdapterPicks.InsertCommand = this.sqlInsertCommand2;
this.SqlDataAdapterPicks.SelectCommand = this.sqlSelectCommand2;
this.SqlDataAdapterPicks.TableMappings.AddRange(new
System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Picks", new
System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("id", "id"),
new System.Data.Common.DataColumnMapping("poolie_ID", "poolie_ID"),
new System.Data.Common.DataColumnMapping("tournament_ID", "tournament_ID"),
new System.Data.Common.DataColumnMapping("golfer_ID", "golfer_ID")})});

Thanks

Derrick

> I will post it tomorrow AM
>
[quoted text clipped - 36 lines]
> > This mail should not be replied directly, please remove the word "online"
> > before sending mail.
"Ying-Shen Yu[MSFT]" - 03 Jul 2004 04:08 GMT
Hi Derrick,

Thanks for your reply,

I read your code carefully, and made a similiar program to try to reproduce
this issue, but it works fine.

Based on my current investigation, listbox will show
"System.Data.DataRowView" in these two situations:
1. the DisplayMember is null or not exist in underlying datasource.
2. An exception was thrown when listbox tries to retrieve text from the
corresponding column of the current DataRowView object.

So you may try checking the following issues:
1. print out the DisplayMember and ValueMember properties after setting
values.
2. run your program with debugger and enable catching CLR exceptions when
the exception is thrown. (You may see the options by clicking menu
"Debug"->"Exceptions") . If you get any exceptions, please include the call
stacks in your reply.
If you see [Non-User code] in your call stack, you may follow the KB
article below to load symbols to get complete call stack information.

<HOW TO: Use a Symbol Server with the Visual Studio .NET Debugger>
http://support.microsoft.com/?id=319037

If you have any updates to this issue, please feel free to post it in this
thread to let me know.
Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
- 08 Jul 2004 21:03 GMT
I fixed it with this code:
       
    dr.fullName=listBoxGolfers.GetItemText
(this.listBoxGolfers.SelectedItem);
   
to replace this code:
   
    dr.fullName=this.listBoxGolfers.SelectedItem.ToStr
ing();

>-----Original Message-----
>Hi Derrick,
[quoted text clipped - 18 lines]
>
>.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.