Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9011037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:37:18+00:00 2026-06-16T02:37:18+00:00

I would like to add some Checkbox in a Grid control dynamically when the

  • 0

I would like to add some Checkbox in a Grid control dynamically when the window is loaded in my C# Desktop application. How many times the checkbox will appear depends on the number of entries in a table. Here, I used LINQ To SQL class.
The Grid control is defined in XAML.

...
<Grid Name="grid1">
   <!-- here i would like to show all check box -->
</Grid>
...

Code behind file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
// class declaration ...
...
private void course_Loaded(object sender, RoutedEventArgs e)
    {
        List<Course> courses = ldc.Courses.ToList();
        foreach (var c in courses)
        {
            CheckBox cb = new CheckBox();
            cb.Name=c.CourseID.ToString();
            cb.Content = c.CourseID.ToString();
            //grid1.Controls.Add(cb); does not work. what to do here?
        }
    }

This code is not working. Any suggession?
Thankyou.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:37:19+00:00Added an answer on June 16, 2026 at 2:37 am

    I suggest adding these CheckBoxes to a StackPanel and then add the StackPanel to the grid:

    StackPanel innerStack;
    
    private void course_Loaded(object sender, RoutedEventArgs e)
    {
        innerStack= new StackPanel 
        {
            Orientation=Orientation.Vertical
        };
        List<Course> courses = ldc.Courses.ToList();
    
        foreach (var c in courses)
        {
            CheckBox cb = new CheckBox();
            cb.Name = c.CourseID.ToString();
            cb.Content = c.CourseID.ToString();
            innerStack.Children.Add(cb);
        }
        Grid.SetColumn(innerStack,  /*Set the column of your stackPanel, default is 0*/);
        Grid.SetRow(innerStack,  /*Set the row of your stackPanel, default is 0*/);
        Grid.SetColumnSpan(innerStack,  /*Set the columnSpan of your stackPanel, default is 1*/);
        Grid.SetRowSpan(innerStack,  /*Set the rowSpan of your stackPanel, default is 1*/);
    
        Grid.Children.Add(innerStack);
    }
    

    If you do not want this structure, you should add some RowDefinition to your grid and use Grid.SetRow(cb, int) method to put ComboBoxes over each other.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to add some paragraphs or new lines or words dynamically but
I would like to add some interactive capability to a python CLI application I've
I would like to add some automated performance test to my Objective-C application. (This
I would like to add some JavaScript inside Blogger. <script type=text/javascript> window.open(http://www.page.html, myWindow, status
I would like to add some animation to my main application tile when it
I would like to add some background music to the splash screen in the
I would like to add some custom data to an image the user generates
I would like to add some data to the body of a http request
I would like to add some debugs for my simple ruby functions and I
I would like to add some external .dll libraries e.g. glut32.dll (but it's only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.