如何在vb.net中填充datagrid时激活按钮控件? [英] how to activate button control when datagrid is filled in vb.net?

查看:102
本文介绍了如何在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.

推荐答案

您需要检查 DataGridViewCell Value 属性是否为null或所以你可以这样做:



You need to check if the Value property of the DataGridViewCell is null or not.So you can do something like:

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



,可以查看..

http://social.msdn.microsoft.com/Forums/en-US/0fa5f291-35d2- 4ecf-afb1-9f52ab959109 / data-grid-in-vbnet [ ^ ]


Or, can view..
http://social.msdn.microsoft.com/Forums/en-US/0fa5f291-35d2-4ecf-afb1-9f52ab959109/data-grid-in-vbnet[^]


然后你需要在搜索按钮上写下这段代码搜索过程

then you need to write this code on your search button after the search process
If DataGridView1.RowCount > 0 Then
    btnSave.Enabled = True
Else
    btnSave.Enabled = False
End If


这篇关于如何在vb.net中填充datagrid时激活按钮控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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