社区
VB
帖子详情
如何判断DataGridView1.Rows(i).Cells(y).Value的值是否为空
kvkensin8
2010-09-03 10:37:12
我下的语句是:
If DataGridView1.Rows(i).Cells(12).Value <> "" Then
messagebox.show("ok")
endif
但时候提示出错:没有为类型DBNull定义运算符“<>”,请问是怎么回事啊?谢谢
...全文
570
3
打赏
收藏
如何判断DataGridView1.Rows(i).Cells(y).Value的值是否为空
我下的语句是: If DataGridView1.Rows(i).Cells(12).Value "" Then messagebox.show("ok") endif 但时候提示出错:没有为类型DBNull定义运算符“”,请问是怎么回事啊?谢谢
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
3 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
wood87654321
2010-09-03
打赏
举报
回复
If Not DataGridView1.Rows(i).Cells(12).Value Is DBNull.Value Then
Peter200694013
2010-09-03
打赏
举报
回复
先判断下是不是DBNull
If DataGridView1.Rows(i).Cells(12).Value is DBNull
taick
2010-09-03
打赏
举报
回复
if not string.isnullorempty(DataGridView1.Rows(i).Cells(12).Value) then
end if
or
If DataGridView1.Rows(i).Cells(12).Value &"" <> "" Then
messagebox.show("ok")
endif
C#
DataGridView
中的常用技巧
dbfC#
DataGridView
中的常用技巧 只列出技巧部分,后面会有补充 0(最基本的技巧). 获取某列中的某行(某单元格)中的内容 this.currentposition = this.
dataGridView
1.BindingContext [this.
dataGridView
1.DataSource, this.
dataGridView
1.DataMember].Position; bookContent = this.database.dataSet.Tables[0].
Rows
[this.currentposition][21].ToString().Trim(); MessageBox.Show(bookContent); 1、自定义列 //定义列宽 this.
dataGridView
1.Columns[0].Width = 80; this.
dataGridView
1.Columns[1].Width = 80; this.
dataGridView
1.Columns[2].Width = 180; this.
dataGridView
1.Columns[3].Width = 120; this.
dataGridView
1.Columns[4].Width = 120; Customize
Cells
and Columns in the Windows Forms
DataGridView
Control by Extending Their Behavior and Appearance Host Controls in Windows Forms
DataGridView
Cells
继承
DataGridView
TextBoxCell 类生成新的Cell类,然后再继承
DataGridView
Column 生成新的Column类,并指定 CellTemplate为新的Cell类。新生成的Column便可以增加到
DataGridView
中去。 2、自动适应列宽 Programmatically Resize
Cells
to Fit Content in the Windows Forms
DataGridView
Control Samples:
DataGridView
.AutoSizeColumns(
DataGridView
AutoSizeColumnCriteria.HeaderAndDisplayed
Rows
);
DataGridView
.AutoSizeColumn(
DataGridView
AutoSizeColumnCriteria.HeaderOnly, 2, false);
DataGridView
.AutoSizeRow(
DataGridView
AutoSizeRowCriteria.Columns, 2, false);
DataGridView
.AutoSize
Rows
(
DataGridView
AutoSizeRowCriteria.HeaderAndColumns, 0,
dataGridView
1.
Rows
.Count, false); 3、可以绑定并显示对象 Bind Objects to Windows Forms
DataGridView
Controls 4、可以改变表格线条风格 Change the Border and Gridline Styles in the Windows Forms
DataGridView
Control Samples: this.
dataGridView
1.GridColor = Color.BlueViolet; this.
dataGridView
1.BorderStyle = BorderStyle.Fixed3D; this.
dataGridView
1.CellBorderStyle =
DataGridView
CellBorderStyle.None; this.
dataGridView
1.RowHeadersBorderStyle = DataGridVie
DataGridView
修改后直接保存到数据库实例程序
C#中
DataGridView
修改后直接保存到数据库实例程序,绝对可用,内附源码,有注释 主要代码: //单元格编辑结束后触发 private void
dataGridView
1_CellEndEdit_1(object sender,
DataGridView
CellEventArgs e) { try { string rowid = this.
dataGridView
1.
Rows
[e.RowIndex].
Cells
[0].
Value
.ToString(); string cellhead =
dataGridView
1.Columns[e.ColumnIndex].DataPropertyName; string cell
value
= this.
dataGridView
1.
Rows
[e.RowIndex].
Cells
[e.ColumnIndex].
Value
.ToString(); if (cellhead == "domain") { cellhead = "[domain]"; } else { } if (cell
value
== "True" && cellhead == "passed") { cell
value
= "1"; } else { if (cellhead == "passed") { cell
value
= "0"; } else { } } string sqlcmd = "update domain_info set " + cellhead + "='" + cell
value
+ "' where id=" + rowid; if (dbo.DBcmd(sqlcmd)) { resultshow.Text = " 编辑成功"; } else { resultshow.Text = " 编辑失败"; } } catch { MessageBox.Show("异常", "错误"); } }
C#
DataGridView
添加新行的2个方法
可以静态绑定数据源,这样就自动为
DataGridView
控件添加 相应的行。假如需要动态为
DataGridView
控件添加新行,方法有很多种,下面简单介绍如何为
DataGridView
控件动态添加新行的两种方 法: 方法一: 代码如下:int index=this.
dataGridView
1.
Rows
.Add();this.
dataGridView
1.
Rows
[index].
Cells
[0].
Value
= “1”; this.
dataGridView
1.
Rows
[index].
Cells
[1].
Value
= “2”; this.
dataGridView
1.
Rows
[index].
Cells
DataGridView
转Excel
public void print(
DataGridView
dataGridView
1) { //导出到execl try { //没有数据的话就不往下执行 if (
dataGridView
1.
Rows
.Count == 0) return; //实例化一个Excel.Application对象 Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); //让后台执行设置为不可见,为true的话会看到打开一个Excel,然后数据在往里写 excel.Visible = false; //新增加一个工作簿,Workbook是直接保存,不会弹出保存对话框,加上Application会弹出保存对话框,
值
为false会报错 excel.Application.Workbooks.Add(true); //生成Excel中列头名称 for (int i = 0; i <
dataGridView
1.Columns.Count; i++) { excel.
Cells
[1, i + 1] =
dataGridView
1.Columns[i].HeaderText; } //把
DataGridView
当前页的数据保存在Excel中 for (int i = 0; i <
dataGridView
1.
Rows
.Count - 1; i++) { for (int j = 0; j <
dataGridView
1.Columns.Count; j++) { if (
dataGridView
1[j, i].
Value
Type == typeof(string)) { excel.
Cells
[i + 2, j + 1] = "'" +
dataGridView
1[j, i].
Value
.ToString(); } else { excel.
Cells
[i + 2, j + 1] =
dataGridView
1[j, i].
Value
.ToString(); } } } //设置禁止弹出保存和覆盖的询问提示框 excel.DisplayAlerts = false; excel.AlertBeforeOverwriting = false; //保存工作簿 excel.Application.Workbooks.Add(true).Save(); //保存excel文件 excel.Save("C:" + "\\KKHMD.xls"); //确保Excel进程关闭 excel.Quit(); excel = null; } catch (Exception ex) { MessageBox.Show(ex.Message, "错误提示"); } }
C#万能打印--winform中打印
dataGridView
表格
1.vs2008,在解决方案中添加现有项目DLLFullPrint,然后在主工程中添加引用,引用这个项目。 2.在界面设计中,添加按钮PrintButton,双击它进入代码界面; 在代码文件中,首先使用using DLLFullPrint; 然后按钮点击事件中写入以下代码: private void printButton_Click(object sender, EventArgs e) { System.Data.DataTable dt = new System.Data.DataTable(); DataRow dr; //设置列表头 foreach (
DataGridView
Column headerCell in
dataGridView
1.Columns) { dt.Columns.Add(headerCell.HeaderText); } foreach (
DataGridView
Row item in
dataGridView
1.
Rows
) { dr = dt.NewRow(); for (int i = 0; i < dt.Columns.Count; i++) { dr[i] = item.
Cells
[i].
Value
.ToString(); } dt.
Rows
.Add(dr); } DataSet dy= new DataSet(); dy.Tables.Add(dt); MyDLL.TakeOver(dy); } 3.运行程序,点击打印按钮,弹出打印界面,调节界面,打印预览,需安装打印机。
VB
16,554
社区成员
110,527
社区内容
发帖
与我相关
我的任务
VB
VB技术相关讨论,主要为经典vb,即VB6.0
复制链接
扫一扫
分享
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章