Home Forums WinForms controls Xceed Grid for WinForms DataSource update problem

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #13940 |

    Hi!

    I am using a DataSet to fill my Xceed Grid. When you prss the Button1 the grid is first initially filled with data from a dataset and also i add an eventhandler to handle events when the value in a cell is changed.

    When i change the value in a cell, I want to update the dataset and set the DataSource property again.
    but… I get an NullReferenceException.
    Anyone know how to avoid this and set the datasource in a proper way?
    Another question, can I get rid of my suspendEvents-variable. Of course i don’t want the CellValueChanged-event to fire when i fill my grid, just when i change it manually.

    private int counter = 0;
    private bool suspendEvents = false;

    private PresentationSet CreatePresentationDataSet()
    {
    PresentationSet presentationSet = new PresentationSet();
    presentationSet.Names.AddNamesRow(“NrChanges: ” + counter.ToString());
    return presentationSet;
    }

    private void cellValueChanged(object sender, EventArgs e)
    {
    if (suspendEvents)
    return;
    PresentationSet presentationSet = CreatePresentationDataSet();
    suspendEvents = true;
    this.gridControl1.DataSource = presentationSet.Names;
    suspendEvents = false;
    }

    private void button1_Click(object sender, System.EventArgs e)
    {
    gridControl1.BeginInit();
    suspendEvents = true;
    PresentationSet presentationSet = this.CreatePresentationDataSet();
    this.gridControl1.DataSource = presentationSet.Names;
    foreach (DataCell cell in gridControl1.DataRowTemplate.Cells)
    cell.ValueChanged +=new EventHandler(cellValueChanged);

    gridControl1.EndInit();
    suspendEvents = false;
    }

    Thanks
    Martin

    Imported from legacy forums. Posted by Martin (had 4754 views)

    User (Old forums)
    Member
    Post count: 23064

    Hello,

    I am facing the same problem.
    Updating datasource generates row change and cell change events – causing more data fetch queries on remote server.
    Controlling events using variables sounds dodgy.

    Any suggestions please!!!!

    Thanks,

    Kapil

    Imported from legacy forums. Posted by kapilkelaiya (had 452 views)

    User (Old forums)
    Member
    Post count: 23064

    You subscribe to the ValueChanged-event in the button1_Click method. I think you should do that only once, and not each time you click the button. So move that code out of the button1_Click, and into the constructor of your form, after the call to InitializeComponent, like this:<code>public Form1() {
    InitializeComponent();
    EventHandler handler = new EventHandler(cellValueChanged);
    foreach(DataCell cell in gridControl1.DataRowTemplate.Cells)
    cell.ValueChanged += handler;
    }</code>
    Secondly, I think you should change your mechanism: it’s better to just bind the grid to a DataSet only once, and then update the existing DataSet instead of creating a new DataSet each time. I used to do this (create new one each time) for one of our smaller internal tools, but that tool got bigger and bigger and now we have to rewrite it because it has become too slow.

    Imported from legacy forums. Posted by Tommy (had 312 views)

    User (Old forums)
    Member
    Post count: 23064

    Hello Tommy,

    Thanks for quick reply,

    Here is my code that runs on in Client/GUI.

    ===================================

    private void frmEstimate_Load(object sender, System.EventArgs e)
    {
    locCostCentres = estimateManager.getCostCentres(this.estimateID);
    grdCostCentres.DataSource = locCostCentres;
    }

    private void refreshEstimate()
    {
    isLoading= true;
    grdCostCentres.BeginInit();

    locCostCentres = estimateManager.getCostCentres(this.estimateID);
    //grdCostCentres.DataSource = locCostCentres;

    grdCostCentres.EndInit();
    isLoading= false;
    }

    ===================================

    if i acquire estimateManager object locally, above mentioned code works fine.

    In case, when i acquire estimateManager object from remote server, eventhough data
    source is set in frmEstimate_Load, i have to uncomment DataSource line and reassign it.
    Ohterwise grid will not display new data.

    Any idea, is this problem with remoting or grid/databinding?

    Regards,

    Kapil

    Imported from legacy forums. Posted by kapilkelaiya (had 345 views)

    User (Old forums)
    Member
    Post count: 23064

    When you say:<code>locCostCentres = estimateManager.getCostCentres(this.estimateID);</code>, a new DataSet is created and assigned to locCostCentres, but the grid is still bound to the previous DataSet. Instead of creating a new DataSet (inside getCostCentres?), you should just update the existing one.
    What does getCostCentres look like?

    Imported from legacy forums. Posted by Tommy (had 299 views)

    User (Old forums)
    Member
    Post count: 23064

    Hello Tommy,

    Thanks agian,

    I understood your point.

    In my case,

    estimateManager object is a MarshalByRefObject, which sits on remote machine.
    estimateManager.getCostCentres() returns dataset which is populated from DAL that again may be running on different machine.

    So as per your suggestion, best way to use grid/databinding is …

    1. provide DataSource once. (in formLoad)
    2. And keep updating the same datasource by clear/populate it.

    And my original question,
    Is there any way to disable events while databinding?
    (Because step 2 is a long route for me. Returned dataset has multiple tables with master/detail relations)

    Regards,

    Kapil

    Imported from legacy forums. Posted by kapilkelaiya (had 584 views)

    User (Old forums)
    Member
    Post count: 23064

    I don’t think there’s a standard way to disable events, but the trick with the boolean variable works quite well. It’s easy to implement, and it just works.

    Imported from legacy forums. Posted by Tommy (had 5580 views)

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.