0

我在我的项目中使用 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);
            }
        }
4

1 回答 1

0

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

于 2013-07-18T11:27:19.360 回答