0
votes

I am creating a listbox with itemsource of type dataview. I want to scroll the listbox to praticular item which is not selected. I am using the following code for selected item.

Code:

Binding listbox:

DataView dv = newDt.DefaultView;
            dv.Sort = "Count Desc";
            lbResult.DataContext = dv;

To get the row based on id:

 var selectResult = from mypro in albumDetails.ToTable().AsEnumerable() where mypro.Field<string>("ID")==search.ID  select mypro;

            if (lbResult.SelectedItem != null)
            {
                lbResult.ScrollIntoView(**lbResult.Items[0]**);
            }

How to get the index if the row in the list box.

Geetha

1
Actually lbTrack.SelectedItem is a viewmodel datacontext object for that list item. You can provide any collection item instead of SelectedItem will bring to view.Ragunathan
I am trying the same. but how to get the item. I am using the following code to get the particular row. var selectResult = from myRow in details.ToTable().AsEnumerable() where myRow .Field<string>("ID")==search.ID select myRow; lbResult.Items.IndexOf(selectResult.ElementAt(0)); but it gives -1 index.Geeth
how to find the index of selectResult row in the listbox?Geeth

1 Answers

0
votes

I don't know what is the albumDetails object. Here is the code to get index from DataView.

 DataRow row = dataview.Select("ID='" + search.ID + "'")[0];
 int i= dataview.Rows.IndexOf(row);