以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]遍历控件 返回控件名称的顺序问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=78001)

--  作者:blsu33
--  发布时间:2015/11/30 13:35:00
--  [求助]遍历控件 返回控件名称的顺序问题
老师,
   遍历控件 返回控件名称的顺序是什么顺序?

问题是这样的 遍历过程中 如出现为空的控件 背景颜色为红色;

假设全部为空,执行代码发现,提示红色控件的顺序混乱;

问下是什么顺序,怎么样能排好顺序?

--  作者:大红袍
--  发布时间:2015/11/30 14:40:00
--  
用一个数值定义好各个要检测的控件的名字。
--  作者:blsu33
--  发布时间:2015/11/30 14:44:00
--  
是不是这个意思

01_BTN....
02_BTN....

--  作者:大红袍
--  发布时间:2015/11/30 14:58:00
--  
以下是引用blsu33在2015/11/30 14:44:00的发言:
是不是这个意思

01_BTN....
02_BTN....

 

不是这个意思。是叫你定义数组。

 

Dim 控件名() As String = {"TextBox1", "TextBox2", "TextBox3"}

 

然后循环这个数组。


--  作者:blsu33
--  发布时间:2015/11/30 18:11:00
--  
老师,
    BeforeClose
下列代码有时候不好使,有时候好使,窗口直接关闭了,为什么呢?

If Tables("备份计划").Current.DataRow.RowState = DataRowState.Unchanged Then\'非空变动的行
    Dim Result As DialogResult=MessageBox.Show("是否保存并退出?","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
    If Result = DialogResult.Yes Then
        For Each bt As WinForm.Control In e.Form.Controls
            Dim Index As Integer=bt.Name.LastIndexOf("_")
            If bt.Name.Contains("_UN_") AndAlso e.Form.Controls(bt.Name).text="" Then
                bt.BackColor=Color.Red
                MessageBox.Show("存在空数据!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning)
                Exit For
            
            End If
        Next
        e.Cancel=True
    Else
        Tables("备份计划").Current.Delete
        Tables("A备份计划").save
    End If
End If

--  作者:大红袍
--  发布时间:2015/11/30 18:28:00
--  
If Tables("备份计划").Current.DataRow.RowState = DataRowState.Unchanged Then\'非空变动的行
    Dim Result As DialogResult=MessageBox.Show("是否保存并退出?","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
    If Result = DialogResult.Yes Then
        For Each bt As WinForm.Control In e.Form.Controls
            Dim Index As Integer=bt.Name.LastIndexOf("_")
            If bt.Name.Contains("_UN_") AndAlso e.Form.Controls(bt.Name).text="" Then
                bt.BackColor=Color.Red
                MessageBox.Show("存在空数据!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning)
                e.Cancel=True
                Exit for
            End If
        Next
       
    Else
        Tables("备份计划").Current.Delete
        Tables("A备份计划").save
    End If
End If

--  作者:blsu33
--  发布时间:2015/11/30 21:13:00
--  
老师 ,
  我原来也是这么写的,发到网上,删除了一部分,还是不对,您再给看看,这么简单的代码,我都搞不定了,我也是醉了。
[upload=rar,管理项目1.rar]viewFile.asp?ID=73518[/uploa]

[此贴子已经被作者于2015/11/30 21:29:51编辑过]

--  作者:大红袍
--  发布时间:2015/11/30 21:24:00
--  
If Tables("表A").Current.DataRow.RowState <> DataRowState.Unchanged Then\'非空变动的行
    Dim Result As DialogResult=MessageBox.Show("是否保存并退出?","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
    If Result = DialogResult.Yes Then
        For Each bt As object In e.Form.Controls
            If bt.Name.Contains("_un_") AndAlso bt.text="" Then
                bt.BackColor=Color.Red
                MessageBox.Show("存在空数据!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning)
                e.Cancel=True
                bt.Select
                Exit For
            Else
                bt.BackColor=Color.White
            End If
        Next
       
    Else
        Tables("表A").Current.Delete
        Tables("表A").save
    End If
End If

--  作者:blsu33
--  发布时间:2015/11/30 21:30:00
--  
For Each bt As object In e.Form.Controls

老师 这是什么意思 重来没这么用过 跪求老师指点迷津!

--  作者:大红袍
--  发布时间:2015/11/30 21:35:00
--  

object是最大的类型,不确定是什么类型的时候,就直接写object