概要
cscの作法、調べてみた。
練習問題、やってみた。
練習問題
sqliteでcomboboxに流し込め。
写真
サンプルコード
using System;
using System.Text;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.Data.Common;
using System.Transactions;
using System.Data.SQLite;
namespace App
{
public partial class Form1: Form {
private Label label;
ComboBox comboBox1;
public Form1() {
Text = "combo test";
ClientSize = new Size(300, 200);
label = new Label();
label.Text = "koko";
label.Font = new Font("Geneva", 12, FontStyle.Regular);
label.Height = 30;
label.Width = 190;
label.Left = 50;
label.Top = 130;
this.Controls.Add(label);
comboBox1 = new ComboBox();
comboBox1.Width = 100;
comboBox1.Height = 25;
comboBox1.Left = 50;
comboBox1.Top = 50;
this.Controls.Add(comboBox1);
SQLiteConnection conn = new SQLiteConnection("Data Source=db0.sqlite;");
conn.Open();
SQLiteCommand command = conn.CreateCommand();
command.CommandText = "SELECT * FROM fruit ORDER BY id ASC";
SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter(command);
DataTable dt = new DataTable();
dataAdapter.Fill(dt);
comboBox1.ValueMember = "id";
comboBox1.DisplayMember = "name";
comboBox1.DataSource = dt;
comboBox1.SelectedIndex = -1;
comboBox1.SelectedValueChanged += comboBox1_TextChanged;
comboBox1.TextChanged += comboBox1_TextChanged;
conn.Close();
}
private void comboBox1_TextChanged(object sender, EventArgs e) {
int n = comboBox1.SelectedIndex;
string str = comboBox1.Text;
string str1 = comboBox1.SelectedValue.ToString();
label.Text = "selected: " + n + " (" + str + ": " + str1 + ")";
}
[STAThread]
public static void Main() {
Application.Run(new Form1());
}
}
}
以上。