我们可以使用与Excel相同的数据网格 [英] Can we used Data grid same as Excel

查看:82
本文介绍了我们可以使用与Excel相同的数据网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建与Excel相同的网格视图

,方案如下:

>在网格/ Excel中选择一个单元格

>在网格/ Excel中按F2

>按下网格/ excel中键盘上的上/下/右/左键br />
>显示网格视图和excel的不同行为



>在Excel中没有任何反应,但选择网格相邻单元格

我们可以像网格视图中的excel一样



我尝试一些R& D onRowEnter事件后索引发生变化

我们可以阻止网格视图在F2被按下后不选择

I am trying to create grid view same as Excel
for scenario as follows :
> select one cell in grid/Excel
>Press F2 in Grid/Excel
>Press up/down/right/left key from keyboard in in grid/excel
> show the different behaviour of grid view and excel

> in Excel nothing happens but in grid adjacent cell is selected
can we do same as excel in grid view

I am try some R & D the index was change after onRowEnter event
can we prevent grid view to not select after F2 is press

推荐答案

你可以用一个大量的工作。



这是一个数据网格,而不是工作单。它用于显示和编辑数据库数据。它不是专为Excel外观/工作而设计的。



在Excel中,当你点击F2时,你正在编辑论坛或单元格中的值。在DataGrid中,您必须在DGV上调用BeginEdit以将单元格置于编辑模式。
You could, with a huge amount of work.

It's a DATA GRID, not a WORKSHEET. It's built to show and edit database data. It's not designed to be an Excel look/work alike.

In Excel, when you hit F2, you're editing the forumla or value in the cell. In the DataGrid, you'd have to call BeginEdit on the DGV to put the cell in Edit mode.


嗨......

完成但是在不同的方式..



1.声明一个变量
Hi....
Its done but in different way..

1. declare one variable
bool IsF2Press = false;





2.创建gride view的关键事件



2.create key down event of gride view

private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.F2)
            {
                IsF2Press = true;
            }
        }



3.使用鼠标点击选择其他行:只是false变量


3. For Selecting other row using mouse click: just false the Variable

private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            IsF2Press = false;
        }



4.与Excel相同。使用Tab的问题:


4. For Same As Excel. issue of "Tab" for this used:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
       {
           if (keyData == Keys.Tab)
           {
               IsF2Press = false; 
           }
           return base.ProcessCmdKey(ref msg, keyData);

       }



5.用于网格视图之外的其他控件


5. for other control out of grid view

private void dataGridView1_MouseLeave(object sender, EventArgs e)
        {
            IsF2Press = false;
        }


生成动态文本框并使用jquery你可以尝试
generate dynamic textbox and using jquery u can try


这篇关于我们可以使用与Excel相同的数据网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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