01.
using
System;
02.
using
System.Collections.Generic;
03.
using
System.ComponentModel;
04.
using
System.Data;
05.
using
System.Drawing;
06.
using
System.Linq;
07.
using
System.Text;
08.
using
System.Windows.Forms;
09.
using
System.Data.SqlClient;
10.
using
books.Class;
11.
12.
namespace
books
13.
{
14.
public
partial
class
Form1 : Form
15.
{
16.
SqlConnection Conn;
17.
SqlCommand com;
18.
SqlDataReader dr;
19.
DataTable dtBookType;
20.
StringBuilder sb;
21.
22.
23.
public
Form1()
24.
{
25.
InitializeComponent();
26.
}
27.
28.
private
void
Form1_Load(
object
sender, EventArgs e)
29.
{
30.
string
strConn;
31.
strConn = DBConnString.strConn;
32.
Conn =
new
SqlConnection();
33.
if
(Conn.State == ConnectionState.Open)
34.
{
35.
Conn.Close();
36.
}
37.
Conn.ConnectionString = strConn;
38.
Conn.Open();
39.
sb =
new
StringBuilder();
40.
41.
sb.Append(
"SELECT * FROM BookType ORDER BY IDBookType;"
);
42.
string
sqlIni;
43.
sqlIni = sb.ToString();
44.
com =
new
SqlCommand();
45.
com.CommandText = sqlIni;
46.
com.CommandType = CommandType.Text;
47.
com.Connection = Conn;
48.
dr = com.ExecuteReader();
49.
50.
if
(dr.HasRows)
51.
{
52.
53.
dtBookType =
new
DataTable();
54.
dtBookType.Load(dr);
55.
checkedListBox1.BeginUpdate();
56.
checkedListBox1.DataSource = dtBookType;
57.
checkedListBox1.DisplayMember =
"NameBookType"
;
58.
checkedListBox1.ValueMember =
"IDBookType"
;
59.
checkedListBox1.CheckOnClick =
true
;
60.
checkedListBox1.EndUpdate();
61.
62.
}
63.
}
64.
65.
private
void
button1_Click(
object
sender, EventArgs e)
66.
{
67.
string
ListChecked =
""
;
68.
foreach
(
object
itm
in
checkedListBox1.CheckedItems)
69.
{
70.
ListChecked += itm.ToString();
71.
}
72.
MessageBox.Show(
"You choose: "
+ListChecked ,
"Message"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
73.
74.
}
75.
}
76.
}