-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcombobox.cs
More file actions
81 lines (69 loc) · 2.06 KB
/
combobox.cs
File metadata and controls
81 lines (69 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace combobox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("select");
comboBox1.Items.Add("year");
comboBox1.Items.Add("month");
comboBox1.Text = "select";
SqlConnection con = new SqlConnection("Data Source=LAPTOP-3G9KFH97;Initial Catalog=master;Integrated Security=true");
SqlCommand cmd = new SqlCommand("select * from student", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
try
{
con.Open();
da.Fill(dt);
comboBox3.DataSource = dt;
comboBox3.DisplayMember = "name";
//comboBox3.ValueMember = "id";
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
da.Dispose();
cmd.Dispose();
con.Close();
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox2.Items.Clear();
if(comboBox1.Text=="year")
{
comboBox2.Items.Add("2019");
comboBox2.Items.Add("2018");
comboBox2.Items.Add("2017");
}
else if(comboBox1.Text=="month")
{
comboBox2.Items.Add("jan");
comboBox2.Items.Add("feb");
comboBox2.Items.Add("mar");
}
}
private void button1_Click(object sender, EventArgs e)
{
comboBox1.Items.RemoveAt(0);
}
}
}