Login to ZARP
Username: Password: Remember me

TOPIC: c#

c# 4 years 3 weeks 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# 4 years 3 weeks 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 Golden Blue Badge
  • Posts: 3539
  • Thanks received: 1186
  • Karma: 0
Last Edit: 4 years 3 weeks ago by bunnyslippers69.
Login or register to post a reply.
The following user(s) said Thank You: Killa Kappa, Knuthulhu

c# 4 years 3 weeks 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.
Time to create page: 0.081 seconds

160 PLAYERS ONLINE

Connect to server View Gametracker DarkRP 1
13/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
0/32
online
Connect to server View Gametracker Prop Hunt
0/42
online
Connect to server View Gametracker Sandbox
0/0
offline
Connect to server Discord
147/784
online
Top