'空值判斷

If IsDBNull(DataGridView1.Item(1, 1).Value) = True Then

DataGridView1.Item(1, 1).Value = "空值"

End If

'删除所有行

DataGridView1.Rows.Clear()

'删除第一行

DataGridView1.Rows.RemoveAt(0)

'删除選定的行

For Each r As DataGridViewRow In DataGridView1.SelectedRows

If Not r.IsNewRow Then

DataGridView1.Rows.Remove(r)

End If

Next

'删除所有列

Me.DataGridView1.Columns.Clear()

'新增一列

Me.DataGridView1.Columns.Add("1", "列1")

'設定列寛

Me.DataGridView1.Columns(0).Width = 100

'關閉重新排序

DataGridView1.Columns(0).SortMode = DataGridViewColumnSortMode.NotSortable

'获取当前被选中的行号

Me.DataGridView1.CurrentCell.RowIndex

'获取当前被选中的列号

Me. DataGridView1.CurrentCell.ColumnIndex

'改變行顏色

DataGridView1.Rows(1 ).DefaultCellStyle.BackColor = Color.Yellow

'改變單元格顏色

Me.DataGridView1.Rows(1).Cells(1).Style.BackColor = Color.Lime

'改變字顏色

Me.DataGridView1.Rows(1).Cells(1).Style.ForeColor = Color.Red

'新增一行

DataGridView1.Rows.Add()

'附與值

DataGridView1.Item(1, 1).Value = 1

'表單選擇

TextBox1.Text = DataGridView1.CurrentRow.Cells("Column1").Value.ToString()

'表單筆數

TextBox1.Text = Me.DataGridView1.RowCount

'長度調整

DataGridView1.Height = Me.Height – 150

'寬度調整

DataGridView1.Width = Me.Width – 80

'列只讀

DataGridView1.Columns(0).ReadOnly = True

'行只讀

DataGridView1. Rows(0).ReadOnly = True

'單元格只讀

DataGridView1(0, i - 1).ReadOnly = True

'DataGridViewEnter

Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean

If msg.WParam.ToInt32() = CInt(Keys.Enter) Then

SendKeys.Send("{Tab}")

Return True

Return MyBase.ProcessCmdKey(msg, keyData)

End Function

'設置單元格位置

DataGridView1.CurrentCell = DataGridView1(0, 0)

'取得當前列寬

TextBox1.Text=Me.DataGridView1.Columns(0).Width

'設置列寬

Me.DataGridView1.Columns(0).Width = drVB.Item(0)

VB.NET datagridview的操作的更多相关文章

  1. vb.net datagridview 使用方法

    目录:  1. 取得或者修改当前单元格的内容  2. 设定单元格只读  3. 不显示最下面的新行  4. 判断新增行  5. 行的用户删除操作的自定义  6. 行.列的隐藏和删除  7. 禁止列或者行 ...

  2. DataGridView常用操作

    一.DataGridView列右击菜单事件处理 (1). 添加一个快捷菜单contextMenuStrip1:(2). 给dataGridView1的CellMouseDown事件添加处理程序: pr ...

  3. DataGridView 相关操作

    一.单元格内容的操作// 取得当前单元格内容 Console.WriteLine(DataGridView1.CurrentCell.Value); // 取得当前单元格的列 Index Consol ...

  4. Winform datagridview相关操作

    datagridview显示行号的2种方法: 方法一: 网上最常见的做法是用DataGridView的RowPostPaint事件在RowHeaderCell中绘制行号: privatevoiddat ...

  5. c# WinForm开发 DataGridView各种操作总结大全

    一.单元格内容的操作 //取得当前单元格内容 Console.WriteLine(DataGridView1.CurrentCell.Value); // 取得当前单元格的列 Index Consol ...

  6. vb listview 的常用操作

    常用操作:获取当前行数和列数: MsgBox "行数:" & ListView1.ListItems.Count & "列数:" & L ...

  7. datagridview数据绑定操作数据库实现增删改查

    DataSet数据集,数据缓存在客户端内存中,支持断开式连接.DataGridView控件绑定DataSet时,它自动的改变的DS的行的状态,而且在做增删改查的时候,可以借助SqlCommandBui ...

  8. VB.NET & DataGridView与数据库的连接

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/huo065000/article/details/37378313      加入删除用户,这就又要 ...

  9. C#.NET,技巧篇(DataGridView线程操作)

    这个系列的文章,主要是平时做C#.NET(Framework 3.5)开发的时候,积累的经验和技巧.我们平时总有这样的体会,遇到一个特别难解决的问题,网上寻它千百度也没能搜索到有用的信息.这时你肯定会 ...

随机推荐

  1. vue路由跳转到指定页面

    1.this.$router.push({name:'Home'}) 2.this.$router.push({path:'/view'}) 3.this.$router.replace({name: ...

  2. [Err] 1418 - This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creator【s

    问题:执行创建函数的sql文件报错如下: [Err] 1418 - This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA ...

  3. JavaWeb核心之Servlet

    servlet规范:包含三个技术点 1)servlet技术 2)filter技术---过滤器 3)listener技术---监听器 Servlet快速入门 实现步骤: 1)创建类实现Servlet接口 ...

  4. cobbler学习

    note.youdao.com/share/?id=2f8383d6e9824929012b041f069da26e&type=note#/ IPADDR=192.168.86.4 TYPE= ...

  5. java 基础--理论知识

    变量分:局部变量全局变量-----------------------------------------------------变量三大特性[标识符,初始值,作用域]定义变量:语法:[访问修饰符] ...

  6. 解决 asp.net core 中下载 exe 文件返回 404

    在 StartUp 中的 Configure 方法添加如下代码即可 app.UseStaticFiles(new StaticFileOptions() { ContentTypeProvider = ...

  7. python pickle模块的使用/将python数据对象序列化保存到文件中

    # Python 使用pickle/cPickle模块进行数据的序列化 """Python序列化的概念很简单.内存里面有一个数据结构, 你希望将它保存下来,重用,或者发送 ...

  8. NLP常用术语解析

    分词(Segment):中英文都存在分词的问题,不过相对来说,英文单词与单词之间本来就有空格进行分割,所以处理起来相对方便.但是中文书写是没有分隔符的,所以分词的问题就比较突出.分词常用的手段可以是基 ...

  9. Scala微服务架构 一

    因为公司的一个项目需求变动会非常频繁,同时改动在可控范围内,加上产品同学喜欢一些超前思维,我们的CTO决定提前开启八门,使用微服务架构. 划重点 微服务架构主要特点: ==独立组件(自主开发升级)== ...

  10. C# 获取Header中的token值

    public CurrentUser currentUser { get { CurrentUser result = new CurrentUser(); //jwt 解密token IJsonSe ...