You can fill you checked list box by two ways.Just simply inserting items by
chekedlistbox.items.add
and by datasource
As below........
You can also give datatable as data source.
NewUserGroup objNewUsrGrp = new NewUserGroup();
try
{
cklbUserGroups.DataSource = null;
cklbUserGroups.DataSource = objNewUsrGrp.GetUserGroups(0);
cklbUserGroups.DisplayMember = "GroupName";
cklbUserGroups.ValueMember = "GroupId";
}
catch (Exception objEx)
{
throw (objEx);
}
Iterating through selected Items/Checked Items to get Selected value....Or the ValueMember of CheckedListBox
for (int aloop = 0; aloop <= cklbUserGroups.Items.Count - 1; aloop++)
{
if (cklbUserGroups.GetItemCheckState(aloop) == CheckState.Checked)
{
cklbUserGroups.SetSelected(aloop, true);
cklbUserGroups.SelectedValue();
MessageBox.Show(cklbUserGroups.SelectedValue.ToString());
}
}
You can add any comments about this
Top Stories Photos on Yahoo! News Photos
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment