Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Listbox help
Message
From
05/05/2004 08:47:41
John Baird
Coatesville, Pennsylvania, United States
 
 
To
All
General information
Forum:
ASP.NET
Category:
Other
Title:
Listbox help
Miscellaneous
Thread ID:
00901143
Message ID:
00901143
Views:
51
Hello:

I'm pulling out my little remaining hair again. I have a list box with about 8 items, the selected item is highlighted at the top of the list. I press a button (cmdMoveDown) and wish to move the selected item 1 item down the list.

I tried this:
public void MoveDown()
{
     int index = this.lstSelected.SelectedIndex;
     int newindex = index + 1;

     DataTable dtSelect = (DataTable)this.lstSelected.DataSource;
     DataRow dr = dtSelect.Rows[index];

     dtSelect.Rows.Remove(dr);
     dtSelect.Rows.InsertAt(dr, newindex);
}
this removes the item at index 0 just fine. But the select doesn't happen and there is a blank line at the bottom of the list.


then i tried this variation:
public void MoveDown()
{
     int index = this.lstSelected.SelectedIndex;
     int newindex = index + 1;

     DataTable dtSelect = (DataTable)this.lstSelected.DataSource;
     DataRow dr = dtSelect.Rows[index];
     DataRow drNew = dtSelect.NewRow();

     foreach(DataColumn dc in dtSelect.Columns)
        drNew[dc.ColumnName] = dr[dc.ColumnName];

     dtSelect.Rows.Remove(dr);
     dtSelect.Rows.InsertAt(drNew, newindex);
}

this variation removed the selected item and added it at the end of the list rather than at new index.

I tried various permutations of this code and could get nothing to work.  Any suggestions?
Next
Reply
Map
View

Click here to load this message in the networking platform