datagridview 的文本消失了
Posted
技术标签:
【中文标题】datagridview 的文本消失了【英文标题】:the text of datagridview disappears 【发布时间】:2013-07-18 10:48:07 【问题描述】:我在我的项目中使用 Telerik 控件(数据网格视图)。但是当我想在数据网格中添加新行时,前一行的文本(bindingSourceService.DataSource = dtservice,bindingSourceUnit.DataSource = dtunit)消失了。 我的 datagridview 有 3 个组合框列。 怎么了?请帮帮我。
我的代码:
public void FactorLoad(object sender, EventArgs e)
try
var cb = new CategoriBll();
DataTable dtcategori = cb.GetAllDataCategori();
bindingSourceCategouri.DataSource = dtcategori;
catch (Exception ex)
ExceptionkeeperBll.LogFileWrite(ex);
private void DataGridViewFactorCellValueChanged(object sender, GridViewCellEventArgs e)
try
var row = DataGridViewFactor.CurrentRow;
if ((row != null) && (row.Cells[0].IsCurrent))
var categoryId = Convert.ToInt32(DataGridViewFactor.CurrentRow.Cells[0].Value);
var sb = new CategoriOptionBll();
DataTable dtservice = sb.ServiceGetById(categoryId);
bindingSourceService.DataSource = dtservice;
if ((row != null) && (row.Cells[1].IsCurrent))
var serviceId = Convert.ToInt32(DataGridViewFactor.CurrentRow.Cells[1].Value);
var cbi = new CostBll();
var dtunit = cbi.CostById(serviceId);
bindingSourceUnit.DataSource = dtunit;
catch (Exception ex)
ExceptionkeeperBll.LogFileWrite(ex);
private void DataGridViewFactorCellEditorInitialized(object sender, GridViewCellEventArgs e)
try
var row = DataGridViewFactor.CurrentRow;
if ((row != null) && (row.Cells[0].IsCurrent))
var categoryId = Convert.ToInt32(DataGridViewFactor.CurrentRow.Cells[0].Value);
var sb = new CategoriOptionBll();
DataTable dtservice = sb.ServiceGetById(categoryId);
bindingSourceService.DataSource = dtservice;
if ((row != null) && (row.Cells[1].IsCurrent))
var serviceId = Convert.ToInt32(DataGridViewFactor.CurrentRow.Cells[1].Value);
var cbi = new CostBll();
var dtunit = cbi.CostById(serviceId);
bindingSourceUnit.DataSource = dtunit;
catch (Exception ex)
ExceptionkeeperBll.LogFileWrite(ex);
【问题讨论】:
先将您的数据插入数据库,然后将此数据源重新加载到您的 Grid :) 【参考方案1】:它会消失,因为数据源中只有 1 个值。尝试向数据源添加值,而不是分配单个值。
【讨论】:
我该怎么做?你能解释一下吗?以上是关于datagridview 的文本消失了的主要内容,如果未能解决你的问题,请参考以下文章