alexpov
alexpov

Reputation: 1188

UltraWinGrid: How to refresh displayed data

i am new to infragistics and to winGrids

I have SQL database with the following table

Costumers
[ID][Name]

In addition , i have UserControl which has winGrid and add\remove buttons.

When the UserControll becomes, active winGrid datasource is bounded to the table

winGrd.DataSource = Tables.Costumers;

When user wants to add\remove data from costumers table he clicks the relevant button. The table is changed accordingly but the displayed data in the grid is not changed. I used

winGrd.Refresh();

but it does no effect

what is the way to do this, Code examples are welcome

thanks

---Edited ---- Adding code:

private void BtnAdd_Click(object sender, System.EventArgs e)
{
        //...

        DB.DataProxy.AddCostumer(txtType.Text);
        winGrd.Refresh();

        //...
}

AddCostumer method eventually calls for the following method that updates the costumer table

public void AddCostumer(string type)
{
        Costumers.InsertOnSubmit(new InsertOnSubmit{ Name = name});
}

Upvotes: 1

Views: 20886

Answers (4)

Danko Valkov
Danko Valkov

Reputation: 1042

If your DataTable is being updated, the UltraGrid should be showing those changes for you. What you could try is to call

ultraGrid1.Rows.Refresh(Infragistics.Win.UltraWinGrid.RefreshRow.ReloadData);

or

ultraGrid1.Rows.Refresh(Infragistics.Win.UltraWinGrid.RefreshRow.RefreshDisplay);

Upvotes: 3

Pablo Rausch
Pablo Rausch

Reputation: 1362

I think it's because you are setting a DataSource that doesn't implements IBindableList which UltraGrid uses for automatically update data it changes. You could try refreshing it manually setting DataSource to null and resetting DataSource again when you need to show new info.

Upvotes: 0

Daniel
Daniel

Reputation: 444

Once you executed the add/remove command, re-pull the data from database and redo the binding. Set the DataGridView.DataSource to null before all that, just in case; you wouldn't want to display wrong data if the connection or any other database-related process fails.

Upvotes: 0

Steve
Steve

Reputation: 216313

Not sure, but, as from MSDN documentation on InsertOnSubmit()

The added entity will not appear in query results from this table until after SubmitChanges has been called.

So, perhaps, if you want the result appear immediately in the Costomers entity and then in the WinGrid, you should call, in the code above the SubmitChanges()

public void AddCostumer(string name) 
{ 
    Costumers.InsertOnSubmit(new Costumers() { Name = name}); 

    // Submit the change to the database.
    try
    {
        db.SubmitChanges();
    }
    catch (Exception e)
    {
       // message to the user???
    }
} 

Upvotes: 2

Related Questions