Click here to Skip to main content
16,018,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
VB
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.
Posted
Comments
Sergey Alexandrovich Kryukov 14-Mar-12 1:10am    
I understand that "description should be much less clear" is written due to the problem with English (which is good enough in fact), but I should insist that -- just the opposite: description should be much more clear. :-)
--SA

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

VB
 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.

VB
  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
 
Share this answer
 
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:

VB
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900