This had stumped me for awhile, I keep returning to it and feel I get a little closer - but honestly, I could be getting further away.
At the bottom is my winform code - directly below is my WPF code.
This kinda works, it is late, 3.30am and I have not perfectly refined it (it doesn't populate sdTB12 for something (might be < length will look at it closely tomorrow. (Edit, just realised it is because it counts from 0 and therefore ends on sdTB11 - i mentioned it was late right?)
My issue is that this will require me to create a foreach loop over the Controls for each bank of 12 textboxes - as you can see in the winform I was able to do this with a single code block rather than 5 sets of foreach loops each one containing an If statement to identify a textbox within that bank.
Anyone able to point me towards a better way?
WPF Code:
WinForm Code:
At the bottom is my winform code - directly below is my WPF code.
This kinda works, it is late, 3.30am and I have not perfectly refined it (it doesn't populate sdTB12 for something (might be < length will look at it closely tomorrow. (Edit, just realised it is because it counts from 0 and therefore ends on sdTB11 - i mentioned it was late right?)
My issue is that this will require me to create a foreach loop over the Controls for each bank of 12 textboxes - as you can see in the winform I was able to do this with a single code block rather than 5 sets of foreach loops each one containing an If statement to identify a textbox within that bank.
Anyone able to point me towards a better way?
WPF Code:
C#:
private void Reload()
{
string DS1 = DataSetOne.CombinedName("DataSet1.txt");
if (File.Exists(DS1))
{
var lines = File.ReadAllLines(DS1);
var lineCount = File.ReadLines(DS1).Count();
for (var i = 0; i < lineCount; i++)
{
if (lines.Length > 2)
{
entries = lines[i].Split(',');
}
foreach (var x in TimeKeeper.Children.OfType<TextBox>())
{
if (x.Name == $"sdTB{i}")
x.Text = entries[0];
}
}
}
WinForm Code:
C#:
public void Reload()
{
if (File.Exists(ctk1.DS1))
{
var lines = File.ReadAllLines(ctk1.DS1);
var lineCount = File.ReadLines(ctk1.DS1).Count();
for (var i = 0; i < lineCount; i++)
{
if (lines.Length > 2)
{
var fields = lines[i].Split(',');
var controlNumber = i + 1;
Controls[$"HoldSD{ controlNumber }"].Text = fields[0];
Controls[$"HoldCode{ controlNumber }"].Text = fields[1];
Controls[$"HoldProj{ controlNumber }"].Text = fields[2];
Controls[$"HoldTime{ controlNumber }"].Text = fields[3];
Controls[$"desctbox{ controlNumber }"].Text = fields[4];
}
else
{
return;
}
}
}
}