- PR -

自動的に、入力セルの変更

投稿者投稿内容
Jubei
ぬし
会議室デビュー日: 2002/03/02
投稿数: 830
お住まい・勤務地: 関西
投稿日時: 2006-02-17 18:30
諸農です。

引用:

待ってるんですが、まったく書き込みがないですが、
この処理はできないんでしょうか?



ベタベタですけど、こんな感じで動きました。

コード:
private void SetTextBoxEvent()
{
    foreach(DataGridTableStyle ts in dataGrid1.TableStyles)
    {
        foreach(DataGridColumnStyle ds in ts.GridColumnStyles)
        {
            DataGridTextBoxColumn tb = ds as DataGridTextBoxColumn;
            if (tb != null)
            {
                tb.TextBox.TextChanged += new EventHandler(GridTextBoxTextChanged);
            }
        }
    }
}

private void GridTextBoxTextChanged(object sender,EventArgs e)
{
    TextBox tb = sender as TextBox;
    if (tb != null)
    {
        string str = tb.Text;
        if (str.Length == 4)
        {
            try
            {
                int.Parse(str);
                if (dataGrid1.CurrentCell.ColumnNumber == dataGrid1.TableStyles[0].GridColumnStyles.Count-1)
                {
                    dataGrid1.CurrentCell =
                        new DataGridCell(
                        dataGrid1.CurrentCell.RowNumber + 1,0);
                }
                else
                {
                    dataGrid1.CurrentCell =
                        new DataGridCell(
                        dataGrid1.CurrentCell.RowNumber,dataGrid1.CurrentCell.ColumnNumber + 1);
                }
            }
            catch(FormatException) { }
            catch(Exception ex)
            {
                throw ex;
            }
        }
    }
}


_________________
諸農和岳
Powered by Turbo Delphi & Microsoft Visual Studio 2005

十兵衛@わんくま同盟
http://blogs.wankuma.com/jubei/

スキルアップ/キャリアアップ(JOB@IT)