Bonjour,
Je suis debutant en C#, j'ai cree un programme qui genere des checkbox à partir d'une BDD, je voudrais savoir si c'est checkbox sont cochés ou pas .
Merci
Version imprimable
Bonjour,
Je suis debutant en C#, j'ai cree un programme qui genere des checkbox à partir d'une BDD, je voudrais savoir si c'est checkbox sont cochés ou pas .
Merci
F5 pour compiler et lancer ton projet, ensuite tu regardes si tes cases sont cochées ou pas.
A mon avis, elles sont cochées si elles le sont et elles ne sont pas cochées si elles ne le sont pas (c'est hautement philosophique).
En fait, j'ai rien compris à ton post :roll: 8O
c'est une methode qui me permet de cree une checkbox dans mon form, lorsque je la coche , je voudrais stocker la valeur .Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 public void draw_checkbox(string name, string text, int posx, int posy) { CheckBox myButton = new CheckBox(); myButton.Name = name; myButton.Text = text; myButton.AutoSize =true; myButton.Location = new Point(posx, posy); myButton.Size = new System.Drawing.Size(60, 20); ActiveForm.Controls.Add(myButton); val += myButton.Size.Width; val2 = myButton.Size.Width; }
donc comment je fais pour savoir si la checkbox est coche
Merci
Je suppose que ActiveForm est un objet Form :
Code:
1
2
3
4
5
6
7
8
9
10 public bool ischecked(string name) { Control control = ActiveForm.Controls.Find(name, true); if(control != null && control is CheckBox) { bool checked = ((CheckBox)control).Checked; return checked; } // exception -> contrôle n'existe pas return false; }
ok Merci .
Je vais teste ca.
ok merci ca marche avec une petite modification.
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 public bool ischecked(string name) { int i; Control[] control = ActiveForm.Controls.Find(name, true); for (i = 0; i < control.Length; i++) { if (control != null && control[i] is CheckBox) { bool checkeds = ((CheckBox)control[i]).Checked; return checkeds; } } // exception -> contrôle n'existe pas return false; }
J'avais pas regardé la signature de la méthode.
En .NET 2 il y a aussi :
Code:
1
2
3
4
5
6
7
8 public bool ischecked(string name) { Control control = ActiveForm.Controls[name]; if(control != null && control is CheckBox) { return ((CheckBox)control).Checked; } return false; }
ok effectivement cela marche aussi :D