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;
}

posted @ 2021-03-15 14:22  奔腾的岩浆  阅读(543)  评论(0编辑  收藏  举报