0

i am using telerik control(data grid view) in my project. but when i want to add new row in data grid, the text of previous rows (bindingSourceService.DataSource = dtservice , bindingSourceUnit.DataSource = dtunit) disappear. my datagridview has 3 combobox column. what is wrong? please help me.

my codes:

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);
            }
        }
samira
  • 1,305
  • 10
  • 37
  • 58
  • Insert your data to database first , and reload this datasource to your Grid :) – zey Jul 18 '13 at 11:44

1 Answers1

0

It will disappear because there will be only 1 value in the data source. Try adding value to the data source rather then assigning single value.

Nisarg Shah
  • 354
  • 1
  • 14