从DataGridView在C#中创建自定义控件 [英] Create Custom Control in C# from DataGridView

查看:91
本文介绍了从DataGridView在C#中创建自定义控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中使用以下代码

 public bool _last创建了一个自定义控件; 
private void SupperDataGridView_KeyDown(object sender,KeyEventArgs e)
{
if(e.KeyCode == Keys.Enter)
{
e.SuppressKeyPress = true;

int iColumn = this.CurrentCell.ColumnIndex;


int iRow = this.CurrentCell.RowIndex;
if(iColumn == this.Columns.Count - 1)
{
if(iRow< this.Rows.Count - 1)
{
this。 CurrentCell = this [0,iRow + 1];
}
其他
{
_last = true;
}

}
其他
{
this.CurrentCell = this [iColumn + 1,iRow];
}
}
}

这在正常情况下工作正常,但是,当我尝试隐藏一两列时,它会给我一个错误。



任何人都可以帮我这个代码吗?我希望当用户按下回车键时,光标应该移动到右侧而不是下一行。如果可能,如果单元格为空,则光标应跳转到下一个单元格。

解决方案

我猜你需要检查列的Visible属性。< br $> b $ b

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn.visible(v = vs.110).aspx [ ^

i have created a Custom Control in C# with following code

public bool _last;
        private void SupperDataGridView_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                e.SuppressKeyPress = true;
              
                int iColumn = this.CurrentCell.ColumnIndex;
                
                
                int iRow = this.CurrentCell.RowIndex;
                if (iColumn == this.Columns.Count - 1)
                {
                    if (iRow < this.Rows.Count - 1)
                    {
                        this.CurrentCell = this [0, iRow + 1];
                    }
                    else
                    {
                        _last = true;
                    }

                }
                else
                {
                    this.CurrentCell = this[iColumn +1,iRow];
                }
            }
        } 

This works fine in normal conditions, but, when i try to hide one or two columns, it gives me an error.

Can anyone help me with this code ? I want that when the user presses the enter-key the cursor should move to the right side rather than to the next row. If possible, if cell is blank, the cursor should jump to the next cell.

解决方案

I'm guessing you need to check the Visible property of the column.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn.visible(v=vs.110).aspx[^]


这篇关于从DataGridView在C#中创建自定义控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆