Reputation: 11184
Try to do next - i want to check if some information is already exist if csv file, if yes - open form with label, and put to this label information from file Code is next:
public void getEventTime(string filePath, string currDate, string currentDateTimeHM)
{
//reading the *.csv file and convert to the array of data
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
//create array for getting any vlaue from string
string[] arrOfData = sr.ReadToEnd().Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
sr.Close();
List<string> lines = new List<string>();
bool status=false;//variable for showing form if event exist
foreach (var l in arrOfData)
{
if (l.Contains(currDate) && l.Contains(currentDateTimeHM))
{
string[] temp = l.Split(',').Take(5).ToArray();
notLabel.Text = temp[1].ToString();
status = true;
}
}
if (status)
{
//show Notification Form
Form NotificationForm = new Notification();
NotificationForm.Visible = true;
}
}
all works perfect - if information exist - new form opens, but notLabel.Text = temp[0].ToString();
this part have return nothing. During debuging i got next
means that code is correct but in strange for me reason result in programm - without this text. where I make some mistake?
Below form with label
checked
few rows from file NotificationDesigner.Form.cs
this.notLabel.AutoSize = true;
this.notLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.notLabel.Location = new System.Drawing.Point(12, 22);
this.notLabel.Name = "notLabel";
this.notLabel.Size = new System.Drawing.Size(34, 13);
this.notLabel.TabIndex = 0;
this.notLabel.Text = "label";
Upvotes: 1
Views: 122
Reputation: 11597
where do you call the method getEventTime
and what is notLabel
.
if the method getEventTime
is called and set the notLabel.Text
but after that the text is set again to string.Empty
that there is the problem, so you should probably search or debug every change to notLabel.Text
.
are you sure the it is notLabel
the it is shown in the form? you can check that by registering to the mouseDown
event and see that it is called when you click on the Label
one more thing, add break;
after your line
status = true;
go to the design and press the label, press F4 and search the name
property, i bet it is not notLabel
:
EDIT
i think i fount your problem
correct me if i'm wrong but this lines
if (status)
{
//show Notification Form
Form NotificationForm = new Notification();
NotificationForm.Visible = true;
}
are happening after you change the text... when what you meant is:
public void getEventTime(string filePath, string currDate, string currentDateTimeHM)
{
Form NotificationForm = new Notification();
//reading the *.csv file and convert to the array of data
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
//create array for getting any vlaue from string
string[] arrOfData = sr.ReadToEnd().Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
sr.Close();
List<string> lines = new List<string>();
bool status=false;//variable for showing form if event exist
foreach (var l in arrOfData)
{
if (l.Contains(currDate) && l.Contains(currentDateTimeHM))
{
string[] temp = l.Split(',').Take(5).ToArray();
NotificationForm.NotText = temp[1].ToString();
status = true;
}
}
if (status)
{
//show Notification Form
NotificationForm.Visible = true;
}
}
and in the notification form do
public string NotText
{
set { notLabel.Text = value; }
}
Upvotes: 1