0

I have two lists:

The first one called _listData and with structure:

public List<GraphData> _gData = new List<GraphData>();
public struct GraphData
{
    public double Temp1;
    public double Temp2;
    public DateTime Date;
    public string Type;
}

The second is populated with data in the same time than the first one (in other words, they will have the same amount of lines - this is important because I want to use Index):

FormA_DataType.GraphDataWithID newData2 = new FormA_DataType.GraphDataWithID();
FormA_DataType.GraphDataWithID();

public struct GraphDataWithID
{
    public int IdHeader;
    public string Type;
}

The information is populated this way:

FormA_DataType.GraphDataWithID newData2 = new FormA_DataType.GraphDataWithID();
FormA_DataType.GraphDataWithID();

public struct GraphDataWithID
{
    public int IdHeader;
    public string Type;
}   
if (!item.Full_File_Name.EndsWith("-B") && !item.Full_File_Name.StartsWith("Load_"))
{ 
    FormA_DataType.GraphData newData = new FormA_DataType.GraphData();
    FormA_DataType.GraphDataWithID newData2 = new FormA_DataType.GraphDataWithID();

    newData.Date = item.Time;
    newData.Temp1 = item.Start_temp;
    newData.Temp2 = item.Start_temp;
    newData.Type = item.Cycle_Type.Replace("Unknown", "");

    newData2.Type = item.Cycle_Type.Replace("Unknown", "");
    newData2.IdHeader = item.Id_Tbl_Data_Type_Ro_Header;

    _gData.Add(newData);
}

I send a table clone of _gData to be used in a Graph. There, the user will change the field "type" with some interaction. Then, I compared what I sent to the graph and what I received from the graph

public bool CheckForDifferenceListInPointCycle()
{
    List<FormA_DataType.GraphData> secondNotFirst = Graph._listData.Except(_gData).ToList();

    if (secondNotFirst.Count>0) // there are differences between the lists
    {
        return true;
    }        
    return false;
}

So, I have the Lines with the difference between what I send to the graph and what I received back from the graph. I need to update these differences in the table "newData2"

  • I know what changed because I can compare the Table before and after "Graph interaction". With this difference, I should get the index of this change and use this index to update the table "NewData2". The Index from _gData and newData2 are the same.

Is there any help that you can think of?

To better understand:


  1. I create two lists at the same time: _gData and newData2;

_gData =

12:45:00 | 140 | 160 | "Unknown"

12:45:00 | 140 | 180| "Temp"

newData2 =

"Unknown" | 45

"Temp" | 49


  1. I send _gData to graph... Then I return:

_listData

12:45:00 | 140 | 160 | "New1"

12:45:00 | 140 | 180| "New2"



I need to update, based on the index, "New1" and "New2" in newData2. So, I will have:

newData2 =

"New1" | 45

"New2" | 49

Finally, the question is:

I need to know how to create the loop to update table "newData2" based on the information from "_gData ".

It will be something similar to this

private void button3_Click(object sender, EventArgs e)
{

    if(CheckForDifferenceListInPointCycle())
    {

        foreach (var x in Graph._listData)
        {
            var itemToChange = newData2.First(d => d.Type == x.Type).Type = x.Type;
        }

    }

}
Fabio Soares
  • 101
  • 2
  • 12
  • So what exactly is the question here? – Lasse V. Karlsen Jul 20 '17 at 16:35
  • Hey @LasseV.Karlsen, I will update the question, but I need to know how to create the loop to update table "newData2" based on the information from "_gData " – Fabio Soares Jul 20 '17 at 16:36
  • 1
    Use a `for` loop? Loop through the index values and compare elements from both collections at each index? – Lasse V. Karlsen Jul 20 '17 at 16:37
  • Use a for loop (or for each?) looping through the index of the differences ( differences between list before and after graph) updating "type" from newData2 – Fabio Soares Jul 20 '17 at 16:39
  • No, *one* for loop, you said the indexes was the same, which I take to assume that you have the same number of elements in the two collections, and their order is the same, meaning that element #14 in one list corresponds to element #14 in the other. Is this not true? – Lasse V. Karlsen Jul 20 '17 at 16:40
  • If I know the index that changed from _listData, yes, this will be the same index from my other table (newData2). For example, in my _gData I have 1000 lines. Comparing _gData with _listData, I know what are my changes. So, I know that line 56, 53, 123, 512 changed. I need to get these same line numbers and update newData2. – Fabio Soares Jul 20 '17 at 16:44
  • But aren't that the same "line numbers" in that other file? It seems your question states that it is. – Lasse V. Karlsen Jul 20 '17 at 17:00
  • Yes, they are the same line number. – Fabio Soares Jul 20 '17 at 17:02
  • So then I'll repeat my original question. What exactly is the question here? It seems you have all the information you're looking for? – Lasse V. Karlsen Jul 20 '17 at 17:02

0 Answers0