Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi i need help! I have a data windows form application that takes information fr

ID: 3919138 • Letter: H

Question

Hi i need help! I have a data windows form application that takes information from files and only Prints info to a datagridview if a a file has a specific title. On the data gridview i am having trouble adding values to one of the columns. I am trying to grab a specific column/row value from a row that say holds a NG value .

I have included a picture. In the picture whenever NG is in the Judge column i want to get the string value of the the cell on the same row in The Test No column to put in my datagridview.

using (FileStream stream = File.Open(x, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (StreamReader reader = new StreamReader(stream))
{

string partNum = "";
string tester = "";
string testNo = "";
string date = "";
string time = "";
string serialNum = "";

while (!reader.EndOfStream)
{

try
{

var line = reader.ReadLine();
if (line.Split(',')[0].Equals("Assy No."))
{
partNum = line.Split(',')[1];


}
if (line.Split(',')[0].Equals("TesterName"))
{
tester = line.Split(',')[1];
}
if (line.Split(',')[0].Equals("Date"))
{
date = line.Split(',')[1];

}
if (line.Split(',')[2].Equals("Time"))
{
time = line.Split(',')[3];
}

if (line.Split(',')[2].Equals("Serial"))
{
serialNum = line.Split(',')[3];

}

if (line.Split(',')[3].Equals("Test No."))
{
  
}
if (line.Split(',')[14].Equals("NG"))
{


DataRow allShiftRow = Construct.MainDataTable.NewRow();
allShiftRow["Part Number"] = partNum;
allShiftRow["TesterName"] = tester;
allShiftRow["Date"] = date;
allShiftRow["Time"] = time;
allShiftRow["Test No."] = testNo;

// allShiftRow["Result"] = line.Split(',')[8];
allShiftRow["SerialNum"] = serialNum;
Construct.MainDataTable.Rows.Add(allShiftRow);

Construct.totalInvalidTest++;


}


}
catch
{

}
}
}
}

application thus far

Serial Time Judge Con Disc Dis Dis P01 P01 P01 01 Unit Seq No. Measure?Upper Lim Upper Lim Lower Lim Lower Lim Data Se Chec Test No. up No. Step No. 0 B001 0 C001 0 A003 0 B003 0 C003 0 D003 0 E003 0 F003 0 A005 0 B005 0 OK 0 OK 0 OK 0 1.7186 ohm 0 1.9028 ohm 0 1.8044 ohm 0 1.922 ohm OK 10 10 10 10 OK 1O P 1O P 1 O P NG 1O P 3 O N 3 O N 0 10 10 10 0 2.0408 ohm 0 1.8063 ohm 0 1.8764 ohm N01 N01 OK 2 OK

Explanation / Answer

When you are reading a line from file using -

var line = reader.ReadLine();

you have only one line content from file which can be all headers or a row with values

So trying to fetch record with

if (line.Split(',')[0].Equals("Assy No."))
{
partNum = line.Split(',')[1];
}

will never give you any value.

I would suggest you to first split all comma separated values in a string array first,

then try to get index of your desired columns i.e. Test No. & Judge.

And after this check for Judge index value in every line and If that matches to "NG" use Test No. value the line.

Find Implementation in bold.

bool readHeader = false;

int indexOfTestNo = 0;

int indexOfJudge = 0;

string testNo = "";

string judge = "";

while (!reader.EndOfStream)

{

var line = reader.ReadLine();

string[] values = line.Split(',');

if (!readHeader)

{

for (int index = 0; index < values.Length; index++)

{

if (values[index].Equals("Test No."))

{

indexOfTestNo = index;

}

if (values[index].Equals("Judge"))

{

indexOfJudge = index;

readHeader = true;

}

}

}

if (values[indexOfJudge].Equals("NG"))

{

testNo = values[indexOfTestNo];

// Add row to the table here.

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote