本文介绍了如何在vb.net中填充datagrid时激活按钮控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在vb.net中有一个表单,其中包含一个用于存储搜索结果的数据网格和一个用于将搜索结果另存为Excel工作表的按钮。只有当数据网格有值时才能启用该按钮...或者我也可以使用try catch来检查数据网格是否有数据网格...请帮我编码。 ...谢谢。
I have a form in vb.net with a data grid to store search results and a button to save the search results as an excel sheet. the button should be enabled only when data grid has values ...or I can also use a try catch to check if the data grid if data grid has values... please help me with the coding. ...thanks.
推荐答案
Public Function IsDataGridViewEmpty(ByRef dataGridView As DataGridView) As Boolean
Dim isEmpty As Boolean
isEmpty = True
For Each row As DataGridViewRow In dataGridView.Rows
For Each cell As DataGridViewCell In row.Cells
If Not String.IsNullOrEmpty(cell.Value) Then
' Check if the string only consists of spaces
If Not String.IsNullOrEmpty(Trim(cell.Value.ToString())) Then
isEmpty = False
Exit For
End If
End If
Next
Next
Return isEmpty
End Function
或,可以查看..
[]
Or, can view..
http://social.msdn.microsoft.com/Forums/en-US/0fa5f291-35d2-4ecf-afb1-9f52ab959109/data-grid-in-vbnet[^]
If DataGridView1.RowCount > 0 Then
btnSave.Enabled = True
Else
btnSave.Enabled = False
End If
这篇关于如何在vb.net中填充datagrid时激活按钮控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!