请问如何使用不同形式的变量,然后单击Datagridview? [英] Ask how to use variables of different Form and click on Datagridview ?

查看:69
本文介绍了请问如何使用不同形式的变量,然后单击Datagridview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请在这个论坛上帮助我您的问题.
我有一个数据库表QL,其中包含"nhanvien"的两列分别是"manv"和"tennv".我创建了连接字符串,创建了一个模块,然后将函数声明truyvan(sql,dt)与字符串sql包含sql query和dt相连,数据表中没有表变量.
我已进行编程,因此,当单击datagridview上的一行时,它将在上面的第二个文本框中显示信息.

具体来说,是此子窗体的一个形式,它的名称为Form1,即文本框的名称和位于其旁边的标签gridview. Formload事件是将数据库"nhanvien"表中的所有数据传输到gridview.
http://i367.photobucket.com/albums/oo114/tuansaker3291/linh%20tinh%20gui%20cac%20dien%20dan/1.jpg

现在我有一个像这样的表格Form2 A:

http://i367.photobucket.com/albums/oo114/tuansaker3291/linh%20tinh%20gui%20cac%20dien%20dan/2.jpg

现在是时候要键入"matim"到上方,然后单击"earing airtime",它将打开Form1并在gridview中选择与要搜索的"manv"一致的显示数据,并向上显示2个文本框,然后当然有风险.

嘿不需要访问Form1的变量以及如何在Form1的datagridview中选择一行.你被困住了,不知道怎么办?希望你能教.我得到了gridview行,并运行所有代码行,以检查是否有任何与该代码相似的代码,但是回过头来在此主题的form1 datagridview框中进行处理.

  As  整数 = Form1.data_dulieu.RowCount 



这是Project,然后到您创建数据库的文件夹命令,创建表,将数据插入表中以帮助您增加高手.我非常感谢...
http://www.mediafire.com/?5pw12bh2a2a2sqc

我的英语不是很好,描述应该不太清楚

p/s:我使用VB.Net 2008和SQL2008.到form1时,该值将过滤网格中的值

您可以做的第一种方法是在表单上重载新的构造函数

  public   class  form1
   
   公共  sub  ()
        InitializeComponent()
   结束  sub 

   私有 _mantim  as  整数 =  0 

   公共  sub  ( byval 指令 as  整数)
        InitializeComponent()
        _mantim = mantim
   结束总和
 结束 

' 然后您将其命名为
  dim  frm  as   new  form1( 33 )
 frm.show 



或者您可以在属性中传递值,例如

  public   class  form1
    私有 _mantim  as  整数 =  0 
    公共 属性 Mantim  as  整数
     获取
       返回 _mantim
     结束 获取
     设置
       _mantim
     结束 设置
    结束 属性
  结束 

' 在form2中,您可以这样称呼它
 dim  frm  as   new  form1
frm.Mantim =  22 
frm.show 



现在,在不知道如何从数据库或使用哪种数据库中获取信息的情况下,我只能建议您相应地更改form1中的查询.如果您需要帮助,请发布一些代码,我们会为您提供更多帮助.


我使用了Simon_Whale的代码,但在键入一系列字符"matim"时仍无法解决问题在Form2中显示"manv"和"tennv"的信息在Form1的两个文本框中,条件为"manv = matim".
在使用Form2 formload的情况下,我使用了以下命令:

 私有  Sub  Form1_Load( ByVal 发​​件人 As 系统.对象 ByVal  e  As  System.EventArgs)句柄  MyBase .加载
        dbs.ConnectionString = MyConnectString
         Dim  sql  As  字符串 = " 
         Dim  dt  As   New  DataTable
        sql = " 
        truyvan(sql,dt)
         .data_dulieu.DataSource = dt
         .data_dulieu.Columns( 0 ).Width =  100 
         .data_dulieu.Columns( 1 ).Width =  300 

         Dim  dong  As  整数 = data_dulieu.Rows .数数
        对于 i  As  整数 =  0  收件人 dong- 1 
            如果 data_dulieu.Rows(i).Cells(" ).Value = Form2.matim.Text " ).Selected = 退出 用于
            结束 如果
        下一步
    结束  




这意味着每次form1 form2都会通过将其称为每周一次来检查gridview的"manv",并将其与Form2中的"matim"进行比较.如果是这样,它将在Form1的gridview行上选择".

问题在于代码是非常合理的,因为它不仅在线上.嗨.正如两个文本字符串所预测的那样,您在Form1的"manv"处是分开的,而不是Form2的文本框"matim"中的相同字符串. (就像在Form2 matim链中一样,后面有更多空间)

因此,Pro可以帮助我进一步解决此问题吗?

谁可以编辑我上面发送的Mediafire链接的项目并发送给我该链接很好,


Please help me your questions in this forum.
I have a database table QL include "nhanvien" has two columns that "manv" and "tennv". I have created the connection string, has created a module and connect the function declaration truyvan (sql, dt) with the string sql contains sql query and dt is the datatable has no table variable into.
I have programmed so that when clicking on a line on the datagridview then it will display information on the second textbox above.

Specifically, a form of this child, and it is named Form1, the name of the textbox and label gridview like standing next to it. Formload event is to transfer all data in the table "nhanvien" of the database to gridview.
http://i367.photobucket.com/albums/oo114/tuansaker3291/linh%20tinh%20gui%20cac%20dien%20dan/1.jpg

Now I have a form like this Form2 A:

http://i367.photobucket.com/albums/oo114/tuansaker3291/linh%20tinh%20gui%20cac%20dien%20dan/2.jpg

Now is when you want to type a "matim" to look above, then click "earn airtime" it will open Form1 and also in gridview are selected in line with "manv" to be searched, and the display data up 2 textbox, then the risk of course.

Hey is not required for access to the variables of Form1 and how to select a row in datagridview of Form1. You''re stuck, do not know how? I hope you teach with. I get the gridview lines and to run all the code line to check whether there is any code similar to the code are not but then looking back to handle in that box of form1 datagridview on the subject.

Dim line As Integer = Form1.data_dulieu.RowCount



Here is the Project and to the folder you create database command, create tables, insert data into the table to help you add high a player. I thank a lot ...
http://www.mediafire.com/?5pw12bh2a2a2sqc

My english is not very good description should be much less clear

p / s: I use VB.Net 2008 and SQL2008.

解决方案

Let me see if I have this correctly, in form2 you enter some value which you want to pass to form1, that value will filter the values in the grid

The first approach that you could do is overload the new constructor on your form

 public class form1
   
   public sub new()
        InitializeComponent()
   end sub

   private _mantim as integer = 0

   public sub new(byval mantim as integer)
        InitializeComponent()
        _mantim = mantim        
   end sum
 end class

' you would then call it like
 dim frm as new form1(33)
 frm.show



or you could pass the values in a property i.e.

  public class form1
    private _mantim as integer = 0
    public property Mantim as integer
     get
       return _mantim
     end get
     set 
       _mantim
     end set
    end property
  end class

'  in form2 you could call it like
dim frm as new form1
frm.Mantim = 22
frm.show



Now without knowing how your get the information from your database or what sort of database you are using I can only then suggest that you alter your query in form1 accordingly. if you need help with that then please post some code and we will help you more


I used the code of Simon_Whale but still does not solve the problem when typing a sequence of characters the "matim" in Form2 that display information "manv" and "tennv" in two textbox in Form1 with the condition that "manv = matim ".
In the event of Form2 formload I have used the following command:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dbs.ConnectionString = MyConnectString
        Dim sql As String = ""
        Dim dt As New DataTable
        sql = "select * from nhanvien"
        truyvan(sql, dt)
        Me.data_dulieu.DataSource = dt
        Me.data_dulieu.Columns(0).Width = 100
        Me.data_dulieu.Columns(1).Width = 300

        Dim dong As Integer = data_dulieu.Rows.Count
        For i As Integer = 0 To dong - 1
            If data_dulieu.Rows(i).Cells("manv").Value = Form2.matim.Text Then
                data_dulieu.Rows(i).Cells("manv").Selected = True
                Exit For
            End If
        Next
    End Sub




This means that each time form1 form2 start by calling it a weekly field checks "manv" of gridview and compared to the "matim" in Form2. if so, it will "select" on gridview row on the Form1.

The problem is that code is very reasonable that it is not just on the line a. hix. As predicted by the two strings of text you are at the "manv" of Form1 is separated is not the same string in textbox "matim" in Form2. (As in Form2 matim chain as more space is at the back)

So Pro can help me solve this problem a little more?

Who can edit the Project that I have sent mediafire link above and send me the link is excellent


这篇关于请问如何使用不同形式的变量,然后单击Datagridview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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