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
2915
the data source for xam data grid not getting updated with correct value in some scenarios
posted

I have a XamDataGrid to display data.

In the ui screen if i update a value, it updates the following

foreach (ViewSetData vsData in paramViewSetVM.CurrentParamsData)
{

for (int i = 0; i < vsData.ParameterData.Rows.Count; i++)

{
if (vsData.ParameterData.Rows[i]["Parameter_Key"].ToString() == paramKey && vsData.ParameterData.Rows[i]["SelCritInstIds"].ToString() == attachedTo)
{

vsData.ParameterData.Rows[i]["Default_Param_Value"] = cmb.DisplayValue.ToString();
vsData.ParameterData.Rows[i]["Default_Param_Version"] = dr[0]["ParameterVersion"].ToString();
found = true;
break;
}
}

if (found)
break;
}

when i save, following code is executed and the data source here has correct updated values.

foreach (UIElement element in panel.Children)
{
if (element.GetType() == typeof(Expander))
{
tempXGrid = null;
Expander tempEx = element as Expander;
tempXGrid = tempEx.Content as XamDataGrid;

if (firstLoop)
{
finalData = ((DataView)tempXGrid.DataSource).Table.Clone();
firstLoop = false;
}
finalData.Merge(((DataView)tempXGrid.DataSource).Table);
}
}

But there is one more way to update the values from ui through the excel sheet. Once i do that the following code runs

paramViewSetVM.CurrentParamsData.Clear();
StackPanel panel = FindName("dataGridPanel") as StackPanel;

// Update the view with the latest data
foreach (UIElement element in panel.Children)
{
if (element.GetType() == typeof(Expander))
{
Expander tempEx = element as Expander;
XamDataGrid tempXGrid = tempEx.Content as XamDataGrid;

foreach (ViewSetData vsData in tmpvsData)
{
if (vsData.ViewSetName == tempEx.Header.ToString())
{
tempXGrid.DataSource = vsData.ParameterData.Copy().DefaultView;
break;
}
}
}
}

tmpvsData.ForEach(vs =>
{
paramViewSetVM.CurrentParamsData.Add(new ViewSetData(vs.ViewSetName, vs.ParameterData.Copy()));
}); // Put the data back in the bound vm data

MainGrid.IsEnabled = true;
tmpvsData.Clear();
importSummaryBrdr.Visibility = System.Windows.Visibility.Collapsed;
MsgPopup.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
MsgPopup.StaysOpen = false;
btnSaveActivate.IsEnabled = true;
btnSaveNotReady.IsEnabled = true;
btnSaveReady.IsEnabled = true;
btnImport.IsEnabled = true;
lblInfo.Content = "Parameters import complete. Recipe will be created with these updated values.";
MsgPopup.IsOpen = true;

Again when i save the data source has correct value.

foreach (UIElement element in panel.Children)
{
if (element.GetType() == typeof(Expander))
{
tempXGrid = null;
Expander tempEx = element as Expander;
tempXGrid = tempEx.Content as XamDataGrid;

if (firstLoop)
{
finalData = ((DataView)tempXGrid.DataSource).Table.Clone();
firstLoop = false;
}
finalData.Merge(((DataView)tempXGrid.DataSource).Table);
}
}

After updating the values from the excel sheet, the data source for xamdatagrid has correct values. But if after this I try to update the value like in the first way, the "ParameterData" has correct values

foreach (ViewSetData vsData in paramViewSetVM.CurrentParamsData)
{

for (int i = 0; i < vsData.ParameterData.Rows.Count; i++)

{
if (vsData.ParameterData.Rows[i]["Parameter_Key"].ToString() == paramKey && vsData.ParameterData.Rows[i]["SelCritInstIds"].ToString() == attachedTo)
{

vsData.ParameterData.Rows[i]["Default_Param_Value"] = cmb.DisplayValue.ToString();
vsData.ParameterData.Rows[i]["Default_Param_Version"] = dr[0]["ParameterVersion"].ToString();
found = true;
break;
}
}

if (found)
break;
}

And now if I do a save again the following code runs, but the data source from where i pick the final value to save still has the value updated from excel sheet only and not the last value i updated again. (the xam datagrid shows the correct value in the ui)

foreach (UIElement element in panel.Children)
{
if (element.GetType() == typeof(Expander))
{
tempXGrid = null;
Expander tempEx = element as Expander;
tempXGrid = tempEx.Content as XamDataGrid;

if (firstLoop)
{
finalData = ((DataView)tempXGrid.DataSource).Table.Clone();
firstLoop = false;
}
finalData.Merge(((DataView)tempXGrid.DataSource).Table);
}
}

Can anyone please help. I am stuck in this.

Any help is greatly appreciated!!

Thanks in advance :)

Parents Reply Children