Login to ZARP
Username: Password: Remember me

TOPIC: c#

c# 3 days 18 hours 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
  • Junior Boarder
  • Ambassador
  • ( ͡⚆ ͜ʖ ͡⚆)╭∩╮
  • Posts: 278
  • Thanks received: 64
  • Karma: 4
Surf Super Admin
Bunny Hop Admin
Teamspeak Admin
Discord Admin

Need to contact me? Steam | Knuthulhu#4528

Login or register to post a reply.

c# 3 days 13 hours ago #1205076

Just get good
  • Huperchild
  • Huperchild's Avatar
  • Offline
  • Mythical Boarder
  • Ambassador
  • still dont know who codabro is
  • Posts: 3982
  • Thanks received: 747
  • Karma: -270
Certified gamer
Certified N word pass owner(given by Micky)
Certified Sinz speaker
Certified Golden Lad
_____________________________________
Former SSRP Admin




Login or register to post a reply.

c# 3 days 11 hours 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
  • Gold Boarder
  • ZARP VIP
  • zarp
  • Posts: 3198
  • Thanks received: 875
  • Karma: 10
Last Edit: 3 days 11 hours ago by Bunnyslippers69.
Login or register to post a reply.
The following user(s) said Thank You: Huperchild, Knuthulhu

c# 2 days 16 hours 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
  • Junior Boarder
  • Ambassador
  • ( ͡⚆ ͜ʖ ͡⚆)╭∩╮
  • Posts: 278
  • Thanks received: 64
  • Karma: 4
Surf Super Admin
Bunny Hop Admin
Teamspeak Admin
Discord Admin

Need to contact me? Steam | Knuthulhu#4528

Login or register to post a reply.
Moderators: RuleBreaker163, Spectrum
Time to create page: 0.165 seconds

237 PLAYERS ONLINE

Connect to server View Gametracker DarkRP 1
24/128
online
Connect to server View Gametracker DarkRP USA
1/128
online
Connect to server View Gametracker Deathrun
0/40
online
Connect to server View Gametracker TTT
40/47
online
Connect to server View Gametracker TTT USA
0/47
online
Connect to server View Gametracker Bhop
6/32
online
Connect to server View Gametracker Surf
17/32
online
Connect to server View Gametracker Prop Hunt
27/42
online
Connect to server View Gametracker TF2 Payload
0/32
online
Connect to server View Gametracker TeamSpeak
22/128
online
Connect to server Discord
100/∞
online
Top