Post: Mods with datagridview checkbox columns
08-24-2015, 11:02 AM #1
seanhellen
Are you high?
(adsbygoogle = window.adsbygoogle || []).push({}); Hi all - I have made a datagridview(DGV) clients list with a cointext menu with mods. This worked fine, but I found it tiresome right-clicking peoples name and selecting mods, then on/off...especially with a laptop touchpad mouse.

So I thought I would make a DGV with checkbox/button columns instead...I have seen it done on here somewhere. The thing is, I can't figure out how to use the checkboxes. I tried something simple like a messagebox popping up when I tick a box, but I just can't get it working...is there a tut or can anyone explain to me how these work?

I have a DGV with the following headers;

client number (text)
client name (text)
godmode (checkbox)
noclip (checkbox)
autokill (checkbox)
Kill (button)
Change Name (button)

I can add rows and populate the number/name columns, but the others I need a hand with Smile

Thanks

***EDIT***
Ok, here is a shot of the table as I want it

You must login or register to view this content.

and this is what I have in my code so far

    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells[5].Value != null)
{
if ((bool)row.Cells[5].Value == true)
{
MessageBox.Show("Success", "Hang On", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}


Now what I dont understand is why I get the test pop-up box when I tick the UAV box...I have specified cell index 5, but to my mind the UAV box is cell index 4 (assuming the index starts with 0 from left to right)

And to make it even worse, cell index 6 does nothing, but cell index 4 is apparently the kill button Eek

Thats the other thing...I can't put text in my buttons for some reason.
(adsbygoogle = window.adsbygoogle || []).push({});

The following user thanked seanhellen for this useful post:

Chen Madhala
08-24-2015, 08:18 PM #2
Chen Madhala
Pokemon Trainer
Originally posted by seanhellen View Post
Hi all - I have made a datagridview(DGV) clients list with a cointext menu with mods. This worked fine, but I found it tiresome right-clicking peoples name and selecting mods, then on/off...especially with a laptop touchpad mouse.

So I thought I would make a DGV with checkbox/button columns instead...I have seen it done on here somewhere. The thing is, I can't figure out how to use the checkboxes. I tried something simple like a messagebox popping up when I tick a box, but I just can't get it working...is there a tut or can anyone explain to me how these work?

I have a DGV with the following headers;

client number (text)
client name (text)
godmode (checkbox)
noclip (checkbox)
autokill (checkbox)
Kill (button)
Change Name (button)

I can add rows and populate the number/name columns, but the others I need a hand with Smile

Thanks

***EDIT***
Ok, here is a shot of the table as I want it

You must login or register to view this content.

and this is what I have in my code so far

    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells[5].Value != null)
{
if ((bool)row.Cells[5].Value == true)
{
MessageBox.Show("Success", "Hang On", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}


Now what I dont understand is why I get the test pop-up box when I tick the UAV box...I have specified cell index 5, but to my mind the UAV box is cell index 4 (assuming the index starts with 0 from left to right)

And to make it even worse, cell index 6 does nothing, but cell index 4 is apparently the kill button Eek

Thats the other thing...I can't put text in my buttons for some reason.


First
About the text
I tried it aswell, look's like the Cell.Text is pretty fu**ed..
So i used this code instead:
    dataGridView1.Rows[0].Cells[6].Value = "Kill";

Just add it to the designer or to the Form1_Load

Second for checkboxes:
First you must use those 2 events:
    
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView1.IsCurrentCellDirty) //So it wont throw exception
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
//Shit here
if (done)
MessageBox.Show(dataGridView1.CurrentRow.Index.ToString());
}


I used a bool "done"
So once you ended adding up all the rows and everything
On the form1_load, in the end put done = true;
Then, it will work fine
Try not to use the bool, you will see what im talking about
Hope that helped Smile
08-25-2015, 08:05 AM #3
seanhellen
Are you high?
Wow, thanks for that reply...I still however cant get it to work. I have copied your code word for word and put the bool in a form1_load (i had to make it...there wasnt one there) but nothing happened.

The text thing didnt work either but I can live without that as I know what they do lol.

One thing I have noticed with my original code is that ticking a box (autokill in my example above...cell index 5) doesnt show a messagebox (like I want) - it enables/disables the other boxes/ buttons to popup the messagebox instead...prob the source of confusion with cell indexes lol.

Obviously what I need is different things being switched on/off depending on the box, not all boxes doing on/off for 1 thing depending on the state of 1 box :confused:
08-25-2015, 06:08 PM #4
Chen Madhala
Pokemon Trainer
Originally posted by seanhellen View Post
Wow, thanks for that reply...I still however cant get it to work. I have copied your code word for word and put the bool in a form1_load (i had to make it...there wasnt one there) but nothing happened.

The text thing didnt work either but I can live without that as I know what they do lol.

One thing I have noticed with my original code is that ticking a box (autokill in my example above...cell index 5) doesnt show a messagebox (like I want) - it enables/disables the other boxes/ buttons to popup the messagebox instead...prob the source of confusion with cell indexes lol.

Obviously what I need is different things being switched on/off depending on the box, not all boxes doing on/off for 1 thing depending on the state of 1 box :confused:


Add my skype: Mango_-Knife

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo