Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
65
newbie: refreshing underlying data from DataTable
posted

Hi forum, probably this is a stupid issue but I cannot find a clue in the documentation: how comes that the grid does not refresh its display when its underlying data from a DataTable get changed? I describe here a dummy sample to reproduce my issue:

 1) in a new WPF application I create a dummy datagrid with 2 fields only, one editable corresponding to a bool field and another non-editable corresponding to a string field:

 <igDP:XamDataGrid VerticalAlignment="Stretch"
      DataSource="{Binding}" x:Name="_dgSample" Margin="2">
 <igDP:XamDataGrid.FieldLayoutSettings>
  <igDP:FieldLayoutSettings AutoGenerateFields="False"
          HighlightAlternateRecords="True"
          AllowAddNew="False" AllowDelete="False"/>
 </igDP:XamDataGrid.FieldLayoutSettings>
 <igDP:XamDataGrid.FieldLayouts>
  <igDP:FieldLayout>
   <igDP:FieldLayout.Fields>
    <igDP:Field Name="selected" Label="sel.">
     <igDP:Field.Settings>
      <igDP:FieldSettings AllowEdit="True"
           CellWidth="40" LabelWidth="40" />
     </igDP:Field.Settings>
    </igDP:Field>
    <igDP:Field Name="name" Label="name">
     <igDP:Field.Settings>
      <igDP:FieldSettings AllowEdit="False"
           CellWidth="150" LabelWidth="150"/>
     </igDP:Field.Settings>
    </igDP:Field>
   </igDP:FieldLayout.Fields>
  </igDP:FieldLayout>
 </igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>

2) in the load event I place this code to create a dummy data source in a DataTable object and bind the grid to it (_dt is a class member of type DataTable):

// create a dummy data table
_dt = new DataTable("TSample");
DataColumn col;

col = new DataColumn("selected", typeof(bool));
col.AllowDBNull = false;
col.DefaultValue = false;
_dt.Columns.Add(col);

col = new DataColumn("name", typeof(string));
col.AllowDBNull = false;
col.DefaultValue = "";
_dt.Columns.Add(col);

// fill it with some data
for (int i = 0; i < 10; i++)
{
 DataRow row = _dt.NewRow();
 row["selected"] = ((i & 1) != 0);
 row["name"] = i.ToString();
 _dt.Rows.Add(row);
} //efor
_dt.AcceptChanges();

// bind to grid
_dgSample.DataSource = new DataView(_dt, "", "name",
 DataViewRowState.CurrentRows);

When I run the sample I get the grid showing the data as expected. If now I click a button which simply inverts the boolean column value, the grid does not show any change:

for (int i = 0; i < _dt.Rows.Count; i++)
 _dt.RowsIdea["selected"] = !(bool)_dt.RowsIdea["selected"];
_dt.AcceptChanges();

What I'm missing here? Thanx to all!

Parents Reply Children
No Data