Jump to content
  • Advertisement
Sign in to follow this  
Kenny77

[C#] Looping Through Datagridview

This topic is 3845 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm looking for a way to loop through my data grid and output the rows to a text file.
TextWriter writer = new StreamWriter("Customers.txt");

for (int i = 0; i < dgvCustomers.Rows.Count; i++)
{
      /* 
      This is where I'm stuck.
      I want to now what parameters
      I need to output the current
      row
       */
      writer.WriteLine();
}

writer.Close();

Share this post


Link to post
Share on other sites
Advertisement
Thanks, but how do I get it to write out the line into a text file? I've tried a bunch of different methods, but all I get is: DataGridViewRow { Index=1 }

Share this post


Link to post
Share on other sites
Quote:
Original post by Kenny77
Thanks, but how do I get it to write out the line into a text file? I've tried a bunch of different methods, but all I get is: DataGridViewRow { Index=1 }

Are you trying to retrieve the value for each column for each row?
it should be something like this (I just showing you the concept; the methods/properties used might not correct, use MSDN or intellisense to find the exact methods & properties:

stringbulder temp = new string builder;
foreach(datagridrow dgr in Datagridrows)
{
// this.dataGridView1.Rows[current row].Cells[current cell].Value
foreach(DataGridViewCell cell in dgr.Cell.Length)
{
temp.append(cell.Value);
}
}

StreamWriter sw=new StreamWriter("c:\\yourfile.txt", true, Encoding.ASCII);
string NextLine=temp.ToString();
sw.Write(NextLine);
sw.Close();


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!