all groups > dotnet windows forms databinding > june 2005 >
You're in the

dotnet windows forms databinding

group:

ListView and Bound DataSet


ListView and Bound DataSet eXtreme
6/6/2005 6:47:22 AM
dotnet windows forms databinding: I have a dataset bound listbox with items that I want to give the user the
ability to reorder.

For some reason... unknown right now... the listbox does not properly update
from the dataset when I update the dataset... even after I accept changes
and write the dataset out to XML.

When I dump the dataset to the Console the data appears to be in the correct
order.

What method would I called to tell the ListBox to refresh from the dataset?

RE: ListView and Bound DataSet v-jetan NO[at]SPAM online.microsoft.com (
6/7/2005 12:00:00 AM
Hi eXtreme,

Thanks for your post.

First, do you use ListView or ListBox in your application? You mentioned
ListView in the post title, however, ListBox in the content. Currently, I
assume you use ListBox.

Normally, we can re-order the databinding with setting a sort expression in
DataView.Sort property. I have writen a little sample project for your
scenario, however, it works well for re-ordering and updating. Code snippet
listed below:

private DataTable dt=null;
private void Form1_Load(object sender, System.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<6;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, System.EventArgs e)
{
this.dt.Rows[3]["column1"]="7";
this.dt.Rows[3]["column2"]="item7";
this.dt.DefaultView.Sort="column1 DESC";
}
===========================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
RE: ListView and Bound DataSet v-jetan NO[at]SPAM online.microsoft.com (
6/9/2005 6:08:25 AM
Hi eXtreme,

Does my reply make sense to you? If you still have anything unclear, please
feel free to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
AddThis Social Bookmark Button