Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Guten Tag!

Ich möchte gerne mehrere Checkboxen überprüfen, ob die angeklickt werden. Dies wollte ich in einer Schleife realisieren. Hier aus dem Forum hatte ich folgendes:


int i = 0;


            for (i = 1; i <= 10; i++)

            {

                this.Controls.Find("Textbox" + Convert.ToString(i), false)[0].Text = "Test";

            }

Dies hab ich dann auf meinen Fall so abgeändert:

int i=0;


for (i = 1; i <= 49; i++)

      {

               if (this.Controls.Find("checkBox" + Convert.ToString(i), false)[0].Checked == true)

                 {

                  //...

                  }

       }

Leider sagt mir Visual Studio, dass es "Checked" nicht kennt.

Ersetzt ich Checked durch Visible funktioniert der Code, aber ich möchte halt gern Prüfen, ob die Checkboxen aktiviert worden sind.

Danke schonmal im Vorraus :)

MfG

Danke für die Schnelle Antwort!

Könntest du mir auch sagen wie man das macht ?

CheckBox chk = Controls.Find("MyControl",true)[0] as CheckBox;
if (chk != null)
{
...
}[/PHP]

Wobei du natürlich eine Exception bekommst wenn er gar kein Control mit der ID findet. Deshalb solltest das auch erstmal prüfen.

Schöner wäre es wenn du einfach durch alle Controls des Elements das deine Checkboxen enthält durchiterierst und da prüfst ob es eine Checkbox ist.

Also

[PHP]
foreach (Control ctrl in Parent.Controls)
{
CheckBox chk = ctrl as CheckBox;
if (chk != null)
{
//Control ist eine CheckBox
}
}

Super!!

Danke es klappt endlich :) :)

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.