wpf datagrid获得选中的多行的行号


private List selectedIndex = null;
///


/// 右键匹配,鼠标按下的时间:获取选中行的行索引
///

///
///
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();
foreach (var sltitem in selectedRows)
{
int rindex = dvgitems.IndexOf(sltitem);
selectedIndex.Add(rindex);
}
if (selectedIndex.Count == 0) selectedIndex = null;
}

相关