Login to ZARP





TOPIC: c#

c# 5 years 3 months ago #1205049

Anyone here good with dataGridViews? Everytime i save the data in adds an empty row and since im saving everytime Form1_FormClosing is called it looks like this:


which is very annoying

The code I use to save is:
string file = Dir + "filename.bin";
using (BinaryWriter bw = new BinaryWriter(File.Open(file, FileMode.Create)))
{
    bw.Write(dataGridView2.Columns.Count);
    bw.Write(dataGridView2.Rows.Count);
    foreach (DataGridViewRow dgvR in dataGridView2.Rows)
    {
        for (int j = 0; j < dataGridView2.Columns.Count; ++j)
        {
            object val = dgvR.Cells[j].Value;
            if (val == null)
            {
                bw.Write(false);
                bw.Write(false);
            }
            else
            {
                bw.Write(true);
                bw.Write(val.ToString());
            }
        }
    }
}
  • Knuthulhu
  • Knuthulhu's Avatar
  • Offline
  • Legendary Member
  • ZARP VIP
  • ¯\_(ツ)_/¯
  • Posts: 579
  • Thanks received: 213
  • Karma: 11


ex Surf & Bhop Server Owner
Login or register to post a reply.

c# 5 years 3 months ago #1205087

Disable AllowUserToAddRows. I think you're writing the default empty row to the file as well as the data you've added yourself. That's what it looks like from the information you've given anyways. If it doesn't work, then feel free to add me on Steam.
  • bunnyslippers69
  • bunnyslippers69's Avatar
  • Offline
  • Diamond Boarder
  • ZARP VIP
  • Posts: 3539
  • Thanks received: 1185
  • Karma: 0
Last Edit: 5 years 3 months ago by bunnyslippers69.
Login or register to post a reply.
The following user(s) said Thank You: Killa Kappa, Knuthulhu

c# 5 years 3 months ago #1205314

Bunnyslippers69 wrote:
Disable AllowUserToAddRows. I think you're writing the default empty row to the file as well as the data you've added yourself. That's what it looks like from the information you've given anyways. If it doesn't work, then feel free to add me on Steam.

This worked, Thank you.

Post can now be locked
  • Knuthulhu
  • Knuthulhu's Avatar
  • Offline
  • Legendary Member
  • ZARP VIP
  • ¯\_(ツ)_/¯
  • Posts: 579
  • Thanks received: 213
  • Karma: 11


ex Surf & Bhop Server Owner
Login or register to post a reply.
Moderators: Clarky

Time to create page: 0.263 seconds

210 PLAYERS ONLINE

Connect to server View Gametracker DarkRP
18/127
Online
Connect to server View Gametracker Deathrun
0/40
Online
Connect to server View Gametracker TTT
0/47
Online
Connect to server View Gametracker Bhop
0/32
Online
Connect to server View Gametracker Surf
5/32
Online
Connect to server View Gametracker Prop Hunt
0/42
Online
Connect to server View Gametracker Sandbox
0/42
Online
Connect to server Discord
187/970
Online
Top