根据其名称以编程方式设置 XAM Datagrid 的选定项目

发布于 2024-12-05 19:53:51 字数 373 浏览 1 评论 0原文

与此类似的事情。

private void SearchResult(string nameOfBean)
{
    foreach (Record VARIABLE in mbeanDataGrid.Records)
    {
        if (VARIABLE.ToString().Contains(nameOfBean))
        {
            ((VARIABLE as DataRecord).DataItem as Record).IsSelected = true;
        }
    }
}

不过我知道这个语法是错误的,我正在寻找一些建议!几乎可以通过代码选择该项目(就像您单击了它一样)。根据它的名字。

Something along the lines of this.

private void SearchResult(string nameOfBean)
{
    foreach (Record VARIABLE in mbeanDataGrid.Records)
    {
        if (VARIABLE.ToString().Contains(nameOfBean))
        {
            ((VARIABLE as DataRecord).DataItem as Record).IsSelected = true;
        }
    }
}

However i know this syntax is wrong and im looking some advice! Pretty much to select the item (As if you had clicked on it) via code. According to its name.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风疏影 2024-12-12 19:53:51

您可以使用以下代码选择记录(如果您想选择多个记录)

private void ShowSearchResult(string searchStr)
{
    var recordsToSelect = new List<Record>();
    foreach (Record rec in xamGrid.Records) {
      var yourData = rec is DataRecord ? ((DataRecord)rec).DataItem as YourDataClass : null;
      if (yourData != null && yourData.MatchWithSearchStr(searchStr)) {
        recordsToSelect.Add(rec);
      }
    }
    xamGrid.SelectedItems.Records.Clear();
    // you need linq -> .ToArray()
    xamGrid.SelectedItems.Records.AddRange(recordsToSelect.ToArray(), false, true);
}

,或者如果您只想激活并选择一条记录,请执行此操作

private void ShowSearchResult(string searchStr)
{
    foreach (Record rec in xamGrid.Records) {
      var yourData = rec is DataRecord ? ((DataRecord)rec).DataItem as YourDataClass : null;
      if (yourData != null && yourData.MatchWithSearchStr(searchStr)) {
        xamGrid.ActiveRecord = rec;
        // don't know if you really need this 
        xamGrid.ActiveRecord.IsSelected = true;
        break;
      }
    }
}

希望这会有所帮助

you can select records with the following code (if you want select more than one record)

private void ShowSearchResult(string searchStr)
{
    var recordsToSelect = new List<Record>();
    foreach (Record rec in xamGrid.Records) {
      var yourData = rec is DataRecord ? ((DataRecord)rec).DataItem as YourDataClass : null;
      if (yourData != null && yourData.MatchWithSearchStr(searchStr)) {
        recordsToSelect.Add(rec);
      }
    }
    xamGrid.SelectedItems.Records.Clear();
    // you need linq -> .ToArray()
    xamGrid.SelectedItems.Records.AddRange(recordsToSelect.ToArray(), false, true);
}

or if you only want to activate and select a record then do this one

private void ShowSearchResult(string searchStr)
{
    foreach (Record rec in xamGrid.Records) {
      var yourData = rec is DataRecord ? ((DataRecord)rec).DataItem as YourDataClass : null;
      if (yourData != null && yourData.MatchWithSearchStr(searchStr)) {
        xamGrid.ActiveRecord = rec;
        // don't know if you really need this 
        xamGrid.ActiveRecord.IsSelected = true;
        break;
      }
    }
}

hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文