为什么我的代码没有被解雇? [英] Why isn't my code firing?

查看:127
本文介绍了为什么我的代码没有被解雇?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在发布之前回顾了相关主题主题。我的问题与我认为的其他问题有点不同。我有一个窗体,在选项卡控件中有一个选项卡控件和一个datagridview。 dgv被绑定,除了1列,它没有绑定。这个列
被称为最后一个视图(我将在下面提供代码)。我有一个组合框,用户可以更改以查看不同的项目。组合框更改时,ProjectID文本框也会更改。当ProjectIDTextBox发生更改时,我会触发许多事件。主要是
我用新数据更新图表。但是,我尝试添加一段新代码,用我需要的信息填充dgv未绑定列。我知道代码有效,因为如果我将它放入Form_Activated事件中,它将起作用;但是,当用户更改他们看到的项目时,这不起作用,因为表单不会"重新激活"。谁能告诉我为什么这样做呢?这是我的代码(我已经省略了私有子中的所有其他代码,因此更容易看到
主要问题)。


 私人小组ProjectIDTextBox_TextChanged(BYVAL发件人为System.Object的,BYVALË作为System.EventArgs)把手ProjectIDTextBox.TextChanged


  对于p As Integer = 0 To Me.BuyerDataGridView.RowCount - 1

            Dim myconn As New SqlConnection

            Dim mycomm As New SqlCommand

            Dim dr2 As SqlDataReader

            Dim dt As New DataTable

            myconn.ConnectionString = QUOT;数据源= .\SQLEXPRESS; AttachDbFilename = C:\Users\David\Documents\ABG Deals.mdf;集成安全性= TRUE;连接超时= 30;用户实例=真"

            myconn.Open()

            mycomm =新的SqlCommand(QUOT; Exec的spLastView '"&安培; Me.BuyerDataGridView.Rows(P).Cells(QUOT; BuyerID")值及安培;。"' " ;,的myconn)

            dr2 = mycomm.ExecuteReader

            dr2。读取
                Me.BuyerDataGridView.Rows(P).Cells(QUOT; LastView")值= dr2.GetValue(0)

        &NBSP ;  结束时
            dr2.Close()

            myconn.Close()

       下一个

   



   结束子


感谢您的帮助。


 

解决方案

< blockquote>

你的方法是用TextBox连接的,而不是用dataGridView连接的,不是吗?这肯定不会起火时组合框在DGV将改变。


您必须解雇一些dgv`s方法,如CellValueChanged什么的。


So I reviewed the related topic threads before posting this. My issue is a bit different than others I believe. I have a form with a tab control and a datagridview in the tab control. The dgv is bound except for 1 column, which is not bound. This column is called last view (I will provide code below). I have a combobox that the user changes to look at different projects. When the combobox changes, the ProjectID text box also changes. I have a number of events that fire when the ProjectIDTextBox changes. Mostly I am updating charts with the new data. However, I have tried to add a new piece of code that will fill in the dgv unbound column with the information that I need. I know that the code works because if I put it into the Form_Activated event, it will work; however, this doesn't work when the user changes the project they look at because the form won't "reactivate". Can anyone tell me why this is doing this? Here is my code (I have omitted all other code in the private sub so that it is easier to see the main problem).

  Private Sub ProjectIDTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProjectIDTextBox.TextChanged

   For p As Integer = 0 To Me.BuyerDataGridView.RowCount - 1
            Dim myconn As New SqlConnection
            Dim mycomm As New SqlCommand
            Dim dr2 As SqlDataReader
            Dim dt As New DataTable
            myconn.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\David\Documents\ABG Deals.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
            myconn.Open()
            mycomm = New SqlCommand("Exec spLastView '" & Me.BuyerDataGridView.Rows(p).Cells("BuyerID").Value & "'", myconn)
            dr2 = mycomm.ExecuteReader
            While dr2.Read
                Me.BuyerDataGridView.Rows(p).Cells("LastView").Value = dr2.GetValue(0)
            End While
            dr2.Close()
            myconn.Close()
        Next
   

    End Sub

Thanks for your help.

 

解决方案

Your method is connected with TextBox, not with dataGridView, isn`t it? This sure wont fire when comboBox in a dgv will change.

You have to fire some of the dgv`s method, like CellValueChanged or something.


这篇关于为什么我的代码没有被解雇?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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