0
1

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.

.netに関わる小ネタ(昔のメモ)

Last updated at Posted at 2020-04-20

#自分用のメモ

FormLoad中のフォーカスセット
FormLoad イベントでは Focus メソッドが効かない。
代わりに、this.ActiveControl = [Control]で設定する。


ミリ秒まで時間を取得
結構よく忘れるので覚書
System.DateTime.Now.ToString("HHmmssfff")


DatasetとDatareaderの速度比
DataSet vs DataReader 検証 .NET2.0
Datareaderのほうが早いっぽい


Form上のTextBoxに対してCtrl+Aで全選択
FormのProcessDialogKeyをオーバーライドするだけ。

    protected override bool ProcessDialogKey(Keys keyData)
    {
        switch (keyData)
        {
            case Keys.A & Keys.Control:
                System.Windows.Forms.Control c = this.ActiveControl;
                if (c.GetType().Equals(typeof(TextBox)))
                {
                    TextBox t = (TextBox)c;
                    t.SelectAll();
                }
                break;
            default:
                break;

        }
        return base.ProcessDialogKey(keyData);
    }

DatasetでDistinctをかけるには、これ。

    System.Data.DataSet ds = new DataSet();
    System.Data.DataTable dt = new DataTable();
    dt = ds.Tables[0].DefaultView.ToTable(true, "DistinctCol1", "DistinctCol2");

ListBoxコントロールで項目の入れ替えなど

	// 項目をあげるボタン
	private void cmd_UP_Click(object sender, EventArgs e)
	{
	    if (lst_img.SelectedItem == null || lst_img.SelectedIndex < 0) { return; }

	    int idx = lst_img.SelectedIndex;
	    if (idx <= 0) { return; }

	    object lo = lst_img.SelectedItem;

	    lst_img.Items.Remove(lst_img.SelectedItem);
	    lst_img.Items.Insert(idx - 1, lo);

	    lst_img.SelectedIndex = idx - 1;
	}

	// 項目をさげるボタン
	private void cmd_DN_Click(object sender, EventArgs e)
	{
	    if (lst_img.SelectedItem == null || lst_img.SelectedIndex < 0) { return; }

	    int idx = lst_img.SelectedIndex;
	    if (idx + 1 >= lst_img.Items.Count) { return; }

	    object lo = lst_img.SelectedItem;

	    lst_img.Items.Remove(lst_img.SelectedItem);
	    lst_img.Items.Insert(idx + 1, lo);

	    lst_img.SelectedIndex = idx + 1;
	}

	// 項目を消すボタン
	private void cmd_RV_Click(object sender, EventArgs e)
	{
	    if (lst_img.SelectedItem == null || lst_img.SelectedIndex < 0) { return; }

	    int idx = lst_img.SelectedIndex;
	    lst_img.Items.Remove(lst_img.SelectedItem);
	    if (lst_img.Items.Count != 0)
	    {
	        lst_img.SelectedIndex = idx - 1;
	        if (idx == 0) { lst_img.SelectedIndex = idx; }
	    }
	}
0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?