DataGridView的是改变数据源在运行后的空白 [英] DataGridView is blank after Changing DataSource at Runtime
问题描述
我在创建它的时候,其中一个表单,我们这个查询
I have a form where when it was created it will this query
public IQueryable<PatientInfo> showMyPatients()
{
DbClassesDataContext myDb = new DbClassesDataContext(dbPath);
var patientInfo = from patients in myDb.PatientInfos
where patients.Phy_ID == physcianID
select patients;
return patientInfo;
}
在我打电话,我将它插入到一个变量,并把它作为一个paramaters这里
Once I call that I will insert it to a variable and pass it as a paramaters here
public void fillDataGrid(IQueryable<PatientInfo> patients)
{
dgvMyPatients.DataSource = patients;
}
听起来很简单吧?但是当我运行此查询
Sounds simple right? but when I run this query
private IQueryable<PatientInfo> searchPatient()
{
DbClassesDataContext myDb = new DbClassesDataContext(dbPath);
var search = from myPatients in myDb.PatientInfos
where (myPatients.Pat_ID == patient_ID && myPatients.Pat_First_Name.Contains(txtSearch.Text)) ||
(myPatients.Pat_ID == patient_ID && myPatients.Pat_Last_Name.Contains(txtSearch.Text)) ||
(myPatients.Pat_ID == patient_ID && myPatients.Pat_Middle_Name.Contains(txtSearch.Text))
select myPatients;
return search;
}
,并将其作为参数传递给 fillDataGrid()
DataGrid中都会有,即使有来自该查询结果为空值
and pass it as a parameter to fillDataGrid()
the DataGrid will have a blank value even though there is a result from that query
BindingSource bs = new BindingSource();
bs.DataSource = searchPatient();
dgvMyPatients.DataSource = bs;
注意:无论是查询返回PATIENTINFO,我会在同一个DataGrid中被插入
推荐答案
我所做的就是,替换我的连接字符串,然后在我的查询变了,似乎有问题,在我的查询洙这就是为什么它不工作。它不产生任何结果。
What I did was, Replace my connection string , then changed in my query, there seems to be problem on my Query soo that is why it is not working. it is not producing any result.
所以,我所做的是,每次我调用此事件,改变我用数据源dgvMyPatients.Columns.Clear();和dgvMyPatients.Refresh();
So what I did was, each time I call this event and change the datasource I use dgvMyPatients.Columns.Clear(); and dgvMyPatients.Refresh();
这篇关于DataGridView的是改变数据源在运行后的空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!