您的位置:首页 > 编程语言 > C#

c# winform 使DataGridView的一些总结

2015-08-24 20:32 381 查看
1:属性设置


设置DataGridView的属性SelectionMode为FullRowSelect 这样就使DataGridView选择一整行了


设置DataGridView的属性MultiSelect为false ,只能选择一行了
,[b]不能够选择多行。
[/b]


[b]使用
ReadOnly 属性
[/b]设置DataGridView的属性ReadOnly为true,DataGridView
内所有单元格都不可编辑

设置DataGridView的AllowUserToAddRows属性为True时,DataGridView的最后一空白行就是新追加的行。

设置DataGridView.ClipboardCopyMode
属性被设定为 DataGridViewClipboardCopyMode.Disable 以外的情况时,「Ctrl + C」按下的时候,被选择的单元格的内容会拷贝到系统剪切板内。格式有: Text, UnicodeText,Html, CommaSeparatedValue。可以直接粘贴到 Excel 内


DataGridView.ShowCellToolTips = True 的情况下,单元格的 ToolTip 可以表示出来。对于单元格窄小,无法完全显示的单元格, ToolTip 可以显示必要的信息。

DataGridView, DataGridViewColumn, DataGridViewRow, DataGridViewCell 有 ContextMenuStrip 属性。可以通过设定 ContextMenuStrip 对象来控制 DataGridView 的右键菜单的显示。 DataGridViewColumn 的 ContextMenuStrip 属性设定了除了列头以外的单元格的右键菜单。 DataGridViewRow 的
ContextMenuStrip 属性设定了除了行头以外的单元格的右键菜单。DataGridViewCell 的  ContextMenuStrip 属性设定了指定单元格的右键菜单。

2:其它

1:右击菜单事件(请先在窗口添加contextMenuStrip控件
 private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)

        {

            if (e.Button == System.Windows.Forms.MouseButtons.Right && e.ColumnIndex > -1 && e.RowIndex > -1)  //点击的是鼠标右键,并且不是表头 

            {

                //右键选中单元格

                this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected = true;

                this.contextMenuStrip1.Show(MousePosition.X, MousePosition.Y);

            }

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: