首页 > 解决方案 > 组合框不正确地过滤 datagridview 数据

问题描述

我面临一个导致过滤器工作不正常的错误 - 也就是说,当我更改组合框中的值时,datagridview 变为空

我使用的代码是:

dataGridView1.DataSource = db.GetInfo()
    .Where(x => x.Title  == cbxSorting.SelectedText)
    .ToList();

标签: c#

解决方案


我不知道为什么,但有时属性“SelectedValue”和“SelectedText”不能正常工作,我建议你使用 SelectedItem

cbxSorting.SelectedItem?.ToString()

推荐阅读