Avatar of Mohammad Alsolaiman
Mohammad Alsolaiman
Flag for Saudi Arabia asked on

Populate checkboxlist with items from database using linq to sql?

Hi:
My table : tblapplicationType
Fields are: Id & applicationType.
Can I Populate checkboxlist with items from tblapplicationType
My context :
dbDataContext db = new dbDataContext();
Would you please, help me writing the suitable code doing so.
Thanks in advance.
Web ApplicationsC#LINQ Query

Avatar of undefined
Last Comment
Mohammad Alsolaiman

8/22/2022 - Mon
SOLUTION
Bob Learned

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Mohammad Alsolaiman

ASKER
IEnumerable! sorry
I'm newbie to c# . I'll watch some videos on that, but acn any one help with the code step by step. please
thanks Bob Learned .
SOLUTION
it_saige

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Mohammad Alsolaiman

ASKER
i try it , but i get this error.
The type or namespace name 'tblapplicationTypes' could not be found (are you missing a using directive or an assembly reference?)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        dbDataContextDataContext dbDataContext = new dbDataContextDataContext();
        private BindingSource source = null;
        private dbDataContextDataContext context = null;
        public Form1()
        {
            InitializeComponent();
            if (context == null)
                context = new dbDataContextDataContext();
            if (source == null)
                source = new BindingSource();
        }

        private void OnLoad(object sender, EventArgs e)
        {
            source.DataSource = context.GetTable(typeof(tblapplicationTypes));
            checkedListBox1.DataSource = source;
            checkedListBox1.DisplayMember = "ApplicationType";
            checkedListBox1.ValueMember = "ID";
        }

        private void OnItemCheck(object sender, ItemCheckEventArgs e)
        {
            MessageBox.Show(string.Format("You have {0} {1}", e.NewValue == CheckState.Checked ? "checked" : "unchecked", (checkedListBox1.Items[e.Index] as tblApplicationType).ApplicationType));
        }
    }
}

Open in new window

please help.
ASKER CERTIFIED SOLUTION
it_saige

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Mohammad Alsolaiman

ASKER
thanks very much to all of you
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck