Groups | Blog | Home
all groups > dotnet windows forms databinding > july 2007 >

dotnet windows forms databinding : update data bound listbox - get "System.Data.DataRowView"


radiolandog
7/1/2007 4:48:26 PM
Hello, World!
Good day to you!

I am using VS 2005 and I have a listbox that is data bound to a column in a
table on a SQL Express database. When I select the "New" button it calls an
openFileDialog. I'd like to put the filename returned from the open file
dialog into the listbox and update the dtabase with that information.

It all seems to work, except for the problem that the first item in the
listbox is displayed as "System.Data.DataRowView" after returning from the
openFileDialog. If I exit and restart the app, everthing is displayed
properly again.

I have the listbox databound to the Form List Instances DataSet, the Display
Member is filetable.name and the Value member is filetable.number (an
identity in the table).

Besides this display artifact, the app works as intended. I am getting the
database updated with the correct values and when I add a file to the list
it gets added properly at the end of the listbox. If I cancel the
openFileDialog, I will still get the first itemdisplayed as
"System.Data.DataRowView" - sometime not right away, but after scrolling up
and down the listbox.

Here's the openFileDialog code (although I'm not sure if it is the problem
area):

if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
title = System.IO.Path.GetFileName(openFileDialog1.FileName);
DataRow newRow = fileDataSet.fileTable.NewRow();
newRow["name"] = title;

fileDataSet.fileTable.Rows.Add(newRow);
fileTableTableAdapter.Update(fileDataSet.fileTable);
}

Any clues?

Thanks, -dog


jetan NO[at]SPAM online.microsoft.com (
7/2/2007 12:00:00 AM
Hi,

Is it possible for you to create a little sample project without the
database dependency to help us reproduce this problem? This will be more
efficient for us to find out the root cause.

Have you setup the ListBox.DisplayMember and ListBox.ValueMember properties
correctly? Normally, you should set these 2 properties to the correct
column name to tell ListBox how to bind. Actually, the following code
snippet works well on my side:

DataTable dt;
private void Form1_Load(object sender, EventArgs e)
{
dt = new DataTable();
dt.Columns.Add(new DataColumn("column1", typeof(int)));
dt.Columns.Add(new DataColumn("column2", typeof(string)));

for (int i = 0; i < 5; i++)
{
DataRow dr = dt.NewRow();
dr["column1"] = i;
dr["column2"] = "item" + i.ToString();
dt.Rows.Add(dr);
}
this.listBox1.DataSource = dt;
this.listBox1.DisplayMember = "column2";
this.listBox1.ValueMember = "column1";
}

private void button1_Click(object sender, EventArgs e)
{
DataRow newRow = dt.NewRow();
newRow["column2"] = "test";
dt.Rows.Add(newRow);
}
You may compare my sample logic with your application logic to see what is
the difference. Please feel free to let me know your finding.

I will wait for your further feedback. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
radiolandog
7/2/2007 9:13:57 PM
I made another app and I could not reproduce the error.
Life is good.. Thanks.


[quoted text, click to view]

jetan NO[at]SPAM online.microsoft.com (
7/3/2007 12:00:00 AM
Hi,

Do you still need any help on this issue? If you still need any help or
have any concern, please feel free to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

AddThis Social Bookmark Button