wpf datagrid获得选中的多行的行号
private List<int> selectedIndex = null;
/// <summary>
/// 右键匹配,鼠标按下的时间:获取选中行的行索引
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SysData_MouseDown(object sender, MouseButtonEventArgs e)
{
int startindex = this.SysData.SelectedIndex;
if (startindex == -1)
{
selectedIndex = null;
return;
}
var selectedRows = this.SysData.SelectedItems;
ItemCollection dvgitems = this.SysData.Items;
selectedIndex = new List<int>();
foreach (var sltitem in selectedRows)
{
int rindex = dvgitems.IndexOf(sltitem);
selectedIndex.Add(rindex);
}
if (selectedIndex.Count == 0) selectedIndex = null;
}