【问题标题】:the text of datagridview disappearsdatagridview 的文本消失了
【发布时间】: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 :)

标签: c# datagridview telerik telerik-grid datagridviewcombobox


【解决方案1】:

它会消失,因为数据源中只有 1 个值。尝试向数据源添加值,而不是分配单个值。

【讨论】:

  • 我该怎么做?你能解释一下吗?
猜你喜欢
  • 2014-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-10
  • 2013-10-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多