Checkboxlist operate in Windows from

Source: Internet
Author: User

1. Use the checkedlistbox1.items. Add Loop Method
 
Assignment:
Foreach (datarow DR in DS. Tables [0]. Rows)
{
Checkedlistbox1.items. Add (Dr ["name"]);
}
 
Selected index:
Foreach (INT indexchecked in checkedlistbox1.checkedindices)
{
MessageBox. Show ("index #:" + indexchecked. tostring ());
}

Selected value:
Foreach (Object itemchecked in chk. checkeditems)
{
MessageBox. Show ("item with title:" + itemchecked. tostring ());
}

2. Use datasource

Assignment:
Checkedlistbox. datasource = Ds. Tables [0];
Checkedlistbox. displaymember = "ID ";
Checkedlistbox. valuemember = "name ";

Selected value:
For (int count = 0; count <checkedlistbox1.checkeditems. Count; count ++)
{
String id = (checkedlistbox1.items [checkedlistbox1.checkedindices [count] As datarowview) ["ID"]. tostring (); // obtain the ID
String name = (checkedlistbox1.items [checkedlistbox1.checkedindices [count] As datarowview) ["name"]. tostring (); // get the name
MessageBox. Show ("ID:" + ID + "name:" + name );
}

 

View code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;


namespace WindowsFormsApplication1
{
public class MatchCalssInitialition
{
public static string originalBinPath = @"C:\Program Files\Kodak\CaptureConsole\Bin\";

public static string excelFilePath = @"D:\DRErrorMessageConfigurationFiles\segscbincidents_error_translations_form_011012_01(old) - Copy.xls";

public static string suffixFileName = "DRErrorMessages.config";

/// <summary>
///
/// </summary>
public enum DRErrorMessage
{
German = 5,
Czech = 6,
Danish = 7,
Greek = 8,
Spanish = 9,
Finnish = 10,
French = 11,
Hungarian = 12,
Italian = 13,
Japanese = 14,
Korean = 15,
Dutch = 16,
Norwegian = 17,
Polish = 18,
Portuguese = 19, //pt-br (Portuguese-LatinAmer : Portuguese Brazil )
PortugueseIberian = 20, //pt-PT (Portuguese)
Romanian = 21,
Russian = 22,
Swedish = 23,
Turkish = 24,
ChineseS = 25, //SimplifiedChinese
ChineseT = 26 //TraditionalChinese
}

/// <summary>
///
/// </summary>
/// <param name="fileType"></param>
/// <returns></returns>
public static Dictionary<int, string> dtGetAllConfigurationFiles()
{

Dictionary<int, string> myDictionaryResult = new Dictionary<int, string>();

#region add key value pair for dictionary.

//myDictionaryResult.Add((int)DRErrorMessage.German, DRErrorMessage.German.ToString() + suffixFileName);
//myDictionaryResult.Add((int)DRErrorMessage.Czech, DRErrorMessage.Czech.ToString() + suffixFileName);
//myDictionaryResult.Add((int)DRErrorMessage.Danish, DRErrorMessage.Danish.ToString() + suffixFileName);
//myDictionaryResult.Add((int)DRErrorMessage.Greek, DRErrorMessage.Greek.ToString() + suffixFileName);
//myDictionaryResult.Add((int)DRErrorMessage.Spanish, DRErrorMessage.Spanish.ToString() + suffixFileName);
//myDictionaryResult.Add((int)DRErrorMessage.Finnish, DRErrorMessage.Finnish.ToString() + suffixFileName);

//myDictionaryResult.Add((int)DRErrorMessage.French, DRErrorMessage.French.ToString() + suffixFileName);
//myDictionaryResult.Add((int)DRErrorMessage.Hungarian, DRErrorMessage.Hungarian.ToString() + suffixFileName);
//myDictionaryResult.Add((int)DRErrorMessage.Italian, DRErrorMessage.Italian.ToString() + suffixFileName);
//myDictionaryResult.Add((int)DRErrorMessage.Japanese, DRErrorMessage.Japanese.ToString() + suffixFileName);
//myDictionaryResult.Add((int)DRErrorMessage.Korean, DRErrorMessage.Korean.ToString() + suffixFileName);
//myDictionaryResult.Add((int)DRErrorMessage.Dutch, DRErrorMessage.Dutch.ToString() + suffixFileName);

//myDictionaryResult.Add((int)DRErrorMessage.Norwegian, DRErrorMessage.Norwegian.ToString() + suffixFileName);
//myDictionaryResult.Add((int)DRErrorMessage.Polish, DRErrorMessage.Polish.ToString() + suffixFileName);
//myDictionaryResult.Add((int)DRErrorMessage.Portuguese, DRErrorMessage.Portuguese.ToString() + suffixFileName); //pt-br (Portuguese-LatinAmer)
//myDictionaryResult.Add((int)DRErrorMessage.PortugueseIberian, DRErrorMessage.PortugueseIberian.ToString() + suffixFileName); //pt-PT (Portuguese)
//myDictionaryResult.Add((int)DRErrorMessage.Romanian, DRErrorMessage.Romanian.ToString() + suffixFileName);
//myDictionaryResult.Add((int)DRErrorMessage.Russian, DRErrorMessage.Russian.ToString() + suffixFileName);

//myDictionaryResult.Add((int)DRErrorMessage.Swedish, DRErrorMessage.Swedish.ToString() + suffixFileName);
//myDictionaryResult.Add((int)DRErrorMessage.Turkish, DRErrorMessage.Turkish.ToString() + suffixFileName);
//myDictionaryResult.Add((int)DRErrorMessage.ChineseS, DRErrorMessage.ChineseS.ToString() + suffixFileName); //SimplifiedChinese
//myDictionaryResult.Add((int)DRErrorMessage.ChineseT, DRErrorMessage.ChineseT.ToString() + suffixFileName); //TraditionalChinese

#endregion

foreach (DRErrorMessage enumDRErrorMessage in Enum.GetValues(typeof(DRErrorMessage)))
{
//myDictionaryResult.Add((int)enumDRErrorMessage, enumDRErrorMessage.ToString() + suffixFileName);
addDictionaryKeyValeuPairs( myDictionaryResult, enumDRErrorMessage);
}

return myDictionaryResult;
}

/// <summary>
///
/// </summary>
/// <param name="columnIndex"></param>
/// <returns></returns>
public static string getSingleConfigurationFilePath(int columnIndex)
{
string path = string.Empty;
Dictionary<int, string> myDictionary = dtGetAllConfigurationFiles();
foreach (KeyValuePair<int, string> keyValue in myDictionary)
{
if (keyValue.Key == columnIndex)
{
path = originalBinPath + keyValue.Value;
break;
}
}
return path;
}

/// <summary>
///
/// </summary>
/// <param name="myDictionary"></param>
/// <param name="drErrorMessage"></param>
public static void addDictionaryKeyValeuPairs( Dictionary<int, string> myDictionary, DRErrorMessage drErrorMessage)
{
int index = (int)drErrorMessage;
if (!myDictionary.Keys.Contains(index))
{
myDictionary.Add(index, drErrorMessage.ToString() + suffixFileName);
}
}
}
}
View code

This. checkedlistbox1.datasource = NULL;
Dictionary <int, string> mydictionaryall = matchcalssinitialition. dtgetallconfigurationfiles ();
If (mydictionaryall. Count = 0) {return ;}

Bindingsource = new bindingsource ();
Bindingsource. datasource = mydictionaryall;
This. checkedlistbox1.datasource = bindingsource;
This. checkedlistbox1.displaymember = "value ";
This. checkedlistbox1.valuemember = "key ";
This. checkedlistbox1.setitemcheckstate (2, checkstate. Checked );

// Foreach (keyvaluepair <int, string> keyvalueall in mydictionaryall)
//{
// This. checkedlistbox1.items. Add (keyvalueall. Value, false );
//}

//// Cyclically traverse checkedlistbox
// For (INT I = 0; I <checkedlistbox1.items. Count; I ++)
//{
//// If selected, execute the following code
// If (this. checkedlistbox1.getitemchecked (I ))
//{
// MessageBox. Show (this. checkedlistbox1.items [I]. tostring ());
//}
//}
Dictionary <int, string> mydictionary = new dictionary <int, string> ();
For (INT I = 0; I <this. checkedlistbox1.items. Count; I ++)
{
// Dictionary <int, string> singledictionary = checkedlistbox1.items [checkedlistbox1.checkedindices [I] As dictionary <int, string>;
If (this. checkedlistbox1.getitemchecked (I ))
{

}
}
If (true) return;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.