Code :
DataTable dt = this.gridGroupingControl1.DataSource as DataTable;
//Commits all the changes made to the table.
dt.AcceptChanges();
Thanks & Regards,
AL.Solai.
Thanks & Regards,
AL.Solai.
Please use Reload() of grid to update the modified values.
Code Example :
this.gridGroupingControl1.Table.Reload();
this.gridGroupingControl1.Refresh();
Thanks,
AL.Solai.
Hi,
I am running into a similar problem regarding the datasource update with GridGroupingControl
I am using Syncfusion Essential Studio 15.2.0.40
I have an observable collection that I am using as the datasource to the control
this.gridGroupingControl1.DataSource = observableCollection_test;
This shows the correct data..
My issue is that when I modify the observable collection the changed data does not display in the control, it displays the same data that was originally loaded. If I close the application and restart it, the correct data will show in the grid.
i.e. I have a checkbox column and if I check that box it marks a flag as true and the grid will only display items that have this flag set to false, therefore when marked as true the observable collection updates that flag en re-queries the db to get the updated results, this is then passed back to the control as the datasource, but the original grid is displayed where that item is still false. If I close the application and re-open it, the information displayed to the user has updated and displays correctly.
I have tried the suggestions in this post already
DataTable dt = this.gridGroupingControl1.DataSource as DataTable;
// This just tells me that dt is null and throws error
dt.AcceptChanges();
// this does not give an error, but does not update the display to the user to show the correct info
this.gridGroupingControl1.Table.Reload();
this.gridGroupingControl1.Refresh();
but it does not work.
what am I doing wrong?
private void AddBtn_Click(object sender, EventArgs e)
{
collection.Add(new Data("54", "Category", "Desc" , "Date" ));
//To refresh the grid
this.gridGroupingControl1.Table.Reload();
this.gridGroupingControl1.TableControl.Refresh();
}
|
//To add the data in observable collection.
collection.Add(new Data("54", "Category", "Desc" , "Date" ));
this.gridGroupingControl1.Table.Reload();
//To refresh only the added rows range
this.gridGroupingControl1.TableControl.RefreshRange(GridRangeInfo.Row(gridGroupingControl1.TableModel.RowCount)); |
Hi Uldis,Thanks for your update.The idea to add and update the values both grid and data source can also be an optimal solution of the reported use case.Please let us know if you have any other queries.Regards,Arulpriya
DataRow rowNew = table.NewRow();
rowNew["Dosage"] = 11;
rowNew["Drug"] = "newDrug";
rowNew["Patient"] = "newPat";
rowNew["Date"] = DateTime.Now;
table.Rows.Add(rowNew);
// must call this to add row in table
table.AcceptChanges();
// it reloads the datatable rows.
this.gridGroupingControl1.Table.Reload(); |
//Update db for Deletion.
void gridGroupingControl1_SourceListRecordChanging(object sender, Syncfusion.Grouping.RecordChangedEventArgs e)
{
if (e.Action == Syncfusion.Grouping.RecordChangedType.Removed)
{
String value = e.Record.GetValue("id").ToString();
string txtSQLQuery = "delete from mains where id =" + value;
ExecuteQuery(txtSQLQuery);
}
}
//Update db for addition.
void gridGroupingControl1_SourceListRecordChanged(object sender, Syncfusion.Grouping.RecordChangedEventArgs e)
{
if (e.Action == Syncfusion.Grouping.RecordChangedType.Added)
{
String column1Value = e.Record.GetValue("id").ToString();
string column2Value = e.Record.GetValue("desc").ToString();
string txtSQLQuery = "insert into mains ([id],[desc]) values ('" + column1Value + "','"+ column2Value + "')";
ExecuteQuery(txtSQLQuery);
}
}
//Update the db when modify the cell value.
void Table_RecordValueChanged(object sender, Syncfusion.Grouping.RecordValueChangedEventArgs e)
{
if (e.Record.Kind == Syncfusion.Grouping.DisplayElementKind.AddNewRecord)
return;
String columnName = e.Column;
Object val = e.Record.GetValue(columnName);
object unique = e.Record.GetValue("id");
if (val == null || unique == null)
return;
string value = val.ToString();
int topRowIndex = this.gridGroupingControl1.Table.Records[0].GetRowIndex();
int i = e.Record.GetRowIndex() - topRowIndex;
string txtSQLQuery = "update mains set " + columnName + " =\"" + value + "\" where id =" + unique.ToString();
ExecuteQuery(txtSQLQuery);
}
private void ExecuteQuery(string txtQuery)
{
SetConnection();
sql_con.Open();
sql_cmd = sql_con.CreateCommand();
sql_cmd.CommandText = txtQuery;
sql_cmd.ExecuteNonQuery();
sql_con.Close();
}
|