Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating Windows application using c# 2010
I am tried to display string value in cell[1] only, but my string value display all cells. How to solve this error any one give me some ideas.

Here I am displaying my code

string test = "2023-24/k-";
string insertValueAs = "\t" + test;


 for (int i = 0; i < dGV.RowCount - 1; i++)
            {
                string stLine = "";
               
                for (int j = 0; j < dGV.Rows[i].Cells.Count; j++)
                stLine = stLine.ToString() + Convert.ToString(dGV.Rows[i].Cells[j].Value) + "\t";

                stLine = stLine.ToString() + Convert.ToString(dGV.Rows[i].Cells[1].Value) + "\t" + test;


                stOutput += stLine +   "\r\n";


              

            }


What I have tried:

I am creating Windows application using c# 2010
I am tried to display string value in cell[1] only, but my string value display all cells. How to solve this error any one give me some ideas.

Here I am displaying my code
Posted
Updated 5-May-23 5:49am

1 solution

THat code doesn't display any information in any cells - it pulls information from all rows, and mashes it together into a single string. What you do with that afterwards we have no idea.

But ... trhe problem may be related to your poor indentation:
for (int j = 0; j < dGV.Rows[i].Cells.Count; j++)
stLine = stLine.ToString() + Convert.ToString(dGV.Rows[i].Cells[j].Value) + "\t";

stLine = stLine.ToString() + Convert.ToString(dGV.Rows[i].Cells[1].Value) + "\t" + test;


stOutput += stLine +   "\r\n";
The inner loop body consists of only the first of those instructions:
stLine = stLine.ToString() + Convert.ToString(dGV.Rows[i].Cells[j].Value) + "\t";
The opther two are part of the body of the outer loop:
for (int i = 0; i < dGV.RowCount - 1; i++)
            {
                string stLine = "";
               
                    ...inner loop ...

                stLine = stLine.ToString() + Convert.ToString(dGV.Rows[i].Cells[1].Value) + "\t" + test;


                stOutput += stLine +   "\r\n";


              

            }
If you indent it correctly, it's a lot more obvious:
string test = "2023-24/k-";
string insertValueAs = "\t" + test;


for (int i = 0; i < dGV.RowCount - 1; i++)
    {
    string stLine = "";
    for (int j = 0; j < dGV.Rows[i].Cells.Count; j++)
        stLine = stLine.ToString() + Convert.ToString(dGV.Rows[i].Cells[j].Value) + "\t";
    stLine = stLine.ToString() + Convert.ToString(dGV.Rows[i].Cells[1].Value) + "\t" + test;
    stOutput += stLine +   "\r\n";
    }
But since it's not at all clear what you expect to acheive, we can't fix it for you!
 
Share this answer
 
Comments
Boopalslm 5-May-23 12:05pm    
DATE BillNo CSTNAME
01-04-23 0:00 2023-24/k-001 MARIMUTHU RANGASAMY
03-04-23 0:00 2023-24/k-002 MARIMUTHU RANGASAMY
10-04-23 0:00 2023-24/k-003 MARIMUTHU RANGASAMY

Sir i need this type of out put
OriginalGriff 5-May-23 12:40pm    
And?
What do you get?

Remember, we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with - we get no other context for your project.

Imagine this: you go for a drive in the country, but you have a problem with the car. You call the garage, say "it broke" and turn off your phone. How long will you be waiting before the garage arrives with the right bits and tools to fix the car given they don't know what make or model it is, who you are, what happened when it all went wrong, or even where you are?

That's what you've done here. So stop typing as little as possible and try explaining things to people who have no way to access your project!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900