在winform中DataGridView的问题,感谢各位高手解答! 本帖最后由 CrazySolo1986 于 2010-11-12 11:52:35 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 DataGridView.DataSource=你查询到的数据 List<Bll.Patient> patients = Bll.Patient.GetPatientInHospital(BedCode, "", Context.Current.User.DP_ID, txtPa_Id.Text.Trim()); dgvPatient.Rows.Clear(); foreach(Bll.Patient patient in patients) { dgvPatient.Rows.Add(); int c = dgvPatient.Rows.Count - 1; DataGridViewRow row = dgvPatient.Rows[c]; row.Cells["pId"].Value = patient.Id; row.Cells["pName"].Value =patient.BedCode+" "+ patient.Name; row.Cells["pPa_Id"].Value = patient.PA_ID; // row.Cells["pBedCode"].Value = patient.BedCode; row.Cells["pBirthday"].Value = patient.Birthday; if (dt.Rows.Count > 0) { dgvType.Rows.Clear(); for (int i = 0; i < dt.Rows.Count; i++) { dgvType.Rows.Add(); int num = dgvType.Rows.Count - 1; DataGridViewRow row = dgvType.Rows[num]; DataRow dr = dt.Rows[i]; row.Cells["tId"].Value = dr["ID"].ToString(); row.Cells["tcode"].Value = dr["DName"].ToString(); row.Cells["tCName"].Value = dr["ChineseName"].ToString(); row.Cells["tType"].Value = dr["TypeName"].ToString() == "Task" ? "医护任务" : "协同消息"; row.Cells["tAreaID"].Value = dr["DAreaID"].ToString(); if (dr["Disabled"].ToString() != "") { row.Cells["tisf"].Value = (bool)dr["Disabled"] ? "启用" : "禁用"; row.Cells["tissend"].Value = (bool)dr["IsAllowSended"] ? "是" : "否"; row.Cells["trea"].Value = dr["Node"].ToString(); } 一种是实体 一种是datatable 直接绑定dataset,觉得这种方法还是可取的 把数据填充到datagridview:dataset.表名.clear();sqldataadapter.fill(dataset.表名);datagridview.datasource=dataset.表名;进行数据更新:你可以直接在datagridview进行修改操作,并结果更新到数据源sqldataadapter.update(dataset.表名);用到sqldataadapter的fill,update这个两个方法 我还在考虑到底是用LISTVIEW好还是DATAGRIDVIEW好呢纠结~~~ winform 进度条 c# 下载图片问题! vs调试不了?并且在VS中打不开web.config的页面 C# 应用程序上使用COM组件后,不能在内部网服务器上运行,能解决吗? 菜鸟提问:送于一个数据绑定问题 求助:如何在一个类中操作另一个类的控件? 水晶报表怎样插入小计 这样的字符串怎样转换? InstalledInputLanguages.count在web应用程序里始终为0 如何调用“发送到(sendto)”功能,或者模拟点右键--发送到 某个特定图标? C#中多表查询结果集中怎样实现显示与更新? 问个编程问题????
dgvPatient.Rows.Clear();
foreach(Bll.Patient patient in patients)
{
dgvPatient.Rows.Add();
int c = dgvPatient.Rows.Count - 1;
DataGridViewRow row = dgvPatient.Rows[c];
row.Cells["pId"].Value = patient.Id;
row.Cells["pName"].Value =patient.BedCode+" "+ patient.Name;
row.Cells["pPa_Id"].Value = patient.PA_ID;
// row.Cells["pBedCode"].Value = patient.BedCode;
row.Cells["pBirthday"].Value = patient.Birthday;
{
dgvType.Rows.Clear();
for (int i = 0; i < dt.Rows.Count; i++)
{
dgvType.Rows.Add();
int num = dgvType.Rows.Count - 1;
DataGridViewRow row = dgvType.Rows[num];
DataRow dr = dt.Rows[i];
row.Cells["tId"].Value = dr["ID"].ToString();
row.Cells["tcode"].Value = dr["DName"].ToString();
row.Cells["tCName"].Value = dr["ChineseName"].ToString();
row.Cells["tType"].Value = dr["TypeName"].ToString() == "Task" ? "医护任务" : "协同消息";
row.Cells["tAreaID"].Value = dr["DAreaID"].ToString();
if (dr["Disabled"].ToString() != "")
{
row.Cells["tisf"].Value = (bool)dr["Disabled"] ? "启用" : "禁用";
row.Cells["tissend"].Value = (bool)dr["IsAllowSended"] ? "是" : "否";
row.Cells["trea"].Value = dr["Node"].ToString();
}
sqldataadapter.fill(dataset.表名);
datagridview.datasource=dataset.表名;
进行数据更新:你可以直接在datagridview进行修改操作,并结果更新到数据源
sqldataadapter.update(dataset.表名);用到sqldataadapter的fill,update这个两个方法