I am getting information from an array and displaying the results in a text box on the form. The value doesn’t get displayed in the UI, but it says that it has the value assigned.
try
{
foreach (string r in Rows)
{
string[] h = new string[5];
h = r.Split(',');
MessageBox.Show(h[0]);
// need to show the first record
House newhouse = new House();
newhouse.ID = Convert.ToInt32(h[0]);
newhouse.Address = Convert.ToString(h[1]);
newhouse.Type = Convert.ToChar(h[2]);
newhouse.Cost = Convert.ToInt32(h[3]);
newhouse.Sold = Convert.ToString(h[4]);
loadedHouses.Add(newhouse);
ID_Number.Text = Convert.ToString(h[0]);
address1.Text = Convert.ToString("g");
type1.Text = Convert.ToString(h[2]);
cost1.Text = Convert.ToString(h[3]);
sold1.Text = Convert.ToString(h[4]);
MessageBox.Show("dewdwedw");
}
}
catch (Exception qq)
{
Console.WriteLine("{0} Exception caught.", qq);
}
When you hover over ID_Number while debugging, it says the value should be 1 but it doesn’t show up in the form. Can anyone help?
Try this…
One can guess whats happening here. The numbers in the textboxes will DISPLAY text from 0 to 999. Right? Wrong…the out put will be just 999 in the end of loop.
I am not an expert and i am trying to learn C#. But I know this code will work the way I am saying. Possibly you will have to do it in a separate thread. Try this…
This code should work as you are expecting.
In the first case also textbox is getting the values continuously from the loop, but not able to display it as the Main thread is already busy. But in second case the thread is separate from the Main thread.
I am not sure it is your problem, but to me it seems so. You are assigning the text to textboxes continuously in a loop. So even though the textboxes have the values but are NOT ABLE TO DISPLAY. If you try creating a new thread, now also textboxes will have the values but will be visible in the textboxes now. Its a kind of pseudo code, just to explain my point. If you are looking for the same, its ok. otherwise throw a stone at my head.
Hope it helps.