views:

267

answers:

1

I have a listview which has its datasource changed after update of a search textbox.

When I enter search criteria that only returns one row, I am unable to trigger the OnSelectionChanged event The listbox works as expected at any other time.

I have tried changing SelectedItem and SelectedIndex in Code, Clicking aimlessly on the ListView both on and off the row and are at the brink of insanity.

Does anyone know of a solution so that I am able to change the selected item!! Help Please

The code I want to run (somehow) is:

private void lstShedBatch_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
try{               
    if (lstShedBatch.SelectedItem != null && lstShedBatch.SelectedIndex != -1)
     {
       ShedBatch currShedBatch = (ShedBatch)this.ShedBatchView.CurrentItem;
       Window1.ShedBatchId = currShedBatch.ShedBatchId;
       Window1.selectedShedId = currShedBatch.ShedId;

       RoutedEventArgs args = new RoutedEventArgs(selectShedBatchClickEvent);
                RaiseEvent(args);
        }
       }
      catch
       {
       }
    }

The problem as stated above, is that this event does not get triggered if the number of items in the list =0 or 1. If there is one record, i want to know what it is and use it to pass variables.

A: 

Then use another trigger. For example TextChanged on your TextBox.

majocha
I have tried on the txtbox code - I get SelectedItem = null
Traci
Could you post the code?
majocha