I have a .csv file like below;
Name,Age,Marks0,Marks 1,Marks2,Marks3
Amal,22,TRUE,FALSE,FALSE,FALSE
Nimal,30,TRUE,TRUE,FALSE,FALSE
Perera,19,TRUE,TRUE,FALSE,FALSE
Sunil,25,TRUE,TRUE,FALSE,FALSE
Amali,22,TRUE,TRUE,FALSE,FALSE
Ann,26,TRUE,TRUE,FALSE,FALSE
Chamath,27,TRUE,FALSE,FALSE,TRUE
Kalana,29,TRUE,FALSE,FALSE,TRUE
Tom,25,TRUE,FALSE,FALSE,TRUE
Jerry,22,TRUE,FALSE,FALSE,TRUE
Peter,23,TRUE,FALSE,FALSE,TRUE
So,I want to read this .csv file and check whether the status of Marks0,Marks1,Marks2,Marks3.After that I want to enable or disable checkbox during the button1 click to browse this file.my interface is like this. Interface of my code
In here want to check status of Marks0,Marks1,Marks2,Marks3 condition is like this,that selected column whole data are TRUE then enable the checkBox.but there are True and False are there then checkBox is enable.but all are False then checkBox is Disable.
An example in here
Marks0 all are TRUE then checkBox1 is enable
Marks1 all are TRUE and FALSE then checkBox2 is enable
Marks2 all are FALSE then checkBox3 is disable
Marks3 all are TRUE and FALSE then checkBox4 is enable like that I want to build my code.
I can enable the checkBox whole column is TRUE and I can disable the checkBox whole column is FALSE but I can not enable the checkBox that there is TRUE and False like Marks1 and Marks3.please give me a solution for this.
My code is following;
private void button1_Click(object sender, EventArgs e)
{
ofd.Filter = "*.csv|*.csv";
ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); //"C:\\BA2000";
fileDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
if (ofd.ShowDialog() == DialogResult.OK)
{
tbOutputFilePath.Text = ofd.FileName;
fileOriginalOutputPath = tbOutputFilePath.Text;
if (tbOutputFilePath != null)
{
List<Marks> ObservingData = new List<Marks>(); // List to store all available Marks objects from the CSV
Marks statusInt = new Marks();
// Loops through each lines in the CSV
foreach (string line in System.IO.File.ReadAllLines(tbOutputFilePath.Text).Skip(1)) // .Skip(1) is for skipping header
{
// here line stands for each line in the csv file
string[] InCsvLine = line.Split(',');
statusInt.Mark0 = (InCsvLine[3] == "TRUE" ? true : false);
statusInt.Mark1 = (InCsvLine[4] == "TRUE" ? true : false);
statusInt.Mark2 = (InCsvLine[5] == "TRUE" ? true : false);
statusInt.Mark3 = (InCsvLine[6] == "TRUE" ? true : false);
}
if (statusInt.Mark0 == false)
{
checkBox1.Enabled = false;
}
if (statusInt.Mark0 == false)
{
checkBox2.Enabled = false;
}
if (statusInt.Mark0 == false)
{
checkBox3.Enabled = false;
}
if (statusInt.Mark0 == false)
{
checkBox4.Enabled = false;
}
}
}
}
}
I created a class to store my column value
class Marks
{
public string Name { get; set; } // property to store Name
public int Age { get; set; } // property to store Age
public bool Marks0 { get; set; } // property to store Marks0
public bool Marks01 { get; set; } // property to store Marks01
public bool Marks2 { get; set; } // property to store Marks2
public bool Marks3 { get; set; } // property to store Marks3
}
Aucun commentaire:
Enregistrer un commentaire