0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

C#のWindowsフォームアプリケーション(.NET Framework)でコンボボックスの設定

Posted at

概要

デフォルトの状態でコンボボックスを設置するとユーザーが編集可能なコンボボックスになってしまうので、ユーザーが選択だけできるコンボボックスを作ります。

image.png

作り方

フォームにコンボボックスを配置

コンボボックスのNameはEnableComboBox
今回のコンボボックスの目的はユーザーに「有効」「無効」を選択させること。

image.png

コード

コンストラクタに初期設定を記載。
SelectedIndexで初期値を設定。
EnableComboBox.DropDownStyle = ComboBoxStyle.DropDownList;は、編集不可の設定。

UserSetForm.cs
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;

namespace WindowsFormsApp1
{
    public partial class UserSetForm : Form
    {
        public UserSetForm()
        {
            InitializeComponent();

            EnableComboBox.Items.Add("有効");
            EnableComboBox.Items.Add("無効");
            EnableComboBox.SelectedIndex = 0;
            EnableComboBox.DropDownStyle = ComboBoxStyle.DropDownList;

        }
    }
}

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?