VB中的事件处理 [英] Event handling in VB

查看:101
本文介绍了VB中的事件处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调用tb1_DataBinding,但它在VB中使用raise事件给出了错误...



在这一行中

 tb1.DataBinding + = New EventHandler(AddressOf tb1_DataBinding)





给出错误DataBinding是一个事件,不能直接调用使用raiseevent语句。

和文本Box是Gridview控件,用于绑定数据,因为GridView具有动态可编辑列。



C#中的链接:



[ ^ ]



但是当我在VB中转换它时会出错。



我尝试了什么:



  Dim  tb1  As   TextBox()
' 分配新的文本框对象。

tb1.DataBinding.Add + = EventHandler( AddressOf tb1_DataBinding)



私有 Sub tb1_DataBinding(sender As Object ,e As EventArgs)
Dim txtdata As TextBox = DirectCast (发件人,TextBox)
Dim 容器 As GridViewRow = DirectCast (txtdata.NamingContainer,GridViewRow)
Dim dataValue 作为 对象 = DataBinder.Eval(container.DataItem,_columnName)
' 如果dataValue<> DBNull.Value然后
txtdata.Text = dataValue.ToString()
' 结束如果
结束 Sub

解决方案

这看起来像是转换不良的C#代码。在VB.NET中,您使用 AddHandler [ ^ ]为事件添加处理程序:

  AddHandler  tb1.DataBinding, AddressOf  tb1_DataBinding 


I am calling tb1_DataBinding but it gives error in VB use raise event...

In This Line

tb1.DataBinding += New EventHandler(AddressOf tb1_DataBinding)



gives error DataBinding is an event and can not be called directly use raiseevent statement.
and text Box is Gridview control for bind data in it because GridView having dynamic editable column.

Link in C# :

[^]

But when I convert It in VB it gives error.

What I have tried:

Dim tb1 As New TextBox()
                'Allocates the new text box object.

                tb1.DataBinding.Add += New EventHandler(AddressOf tb1_DataBinding)



 Private Sub tb1_DataBinding(sender As Object, e As EventArgs)
        Dim txtdata As TextBox = DirectCast(sender, TextBox)
        Dim container As GridViewRow = DirectCast(txtdata.NamingContainer, GridViewRow)
        Dim dataValue As Object = DataBinder.Eval(container.DataItem, _columnName)
        ' If dataValue <> DBNull.Value Then
        txtdata.Text = dataValue.ToString()
        ' End If
    End Sub

解决方案

That looks like poorly-converted C# code. In VB.NET, you use AddHandler[^] to add a handler to an event:

AddHandler tb1.DataBinding, AddressOf tb1_DataBinding


这篇关于VB中的事件处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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