开发者

WPF ListView Cannot Trigger Selection Changed when only one row

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 = cur开发者_JAVA百科rShedBatch.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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜