How to display in the Controls value Form(Windows Forms) of the usercontrol(Windowd Forms) vb.net

jewel 1,186 Reputation points
2021-11-17T07:26:16.95+00:00

I am trying to create a project on VB.net.
I have used the usercontrol form (Name=uc_Daily_sale) as the form. Where datagridview,
dattympicar is attached. At runtime, when I Double click on this DataGridView2_CellDoubleClick Evint,
a Form(Name=frm_DailySaleSummary) opens. A datagridview is attached to this form and the SQL query is displayed there.
I mentioned the query below.
The problem is that in the coding in the load event of frm_DailySaleSummary,
I want to bring the value of the Controls of the usercontrol form. But that is not happening.
Thanks in advance to the experienced collaborators.
Private Sub DataGridView2_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView2.CellDoubleClick
frm_DailySaleSummary.Show()
End Sub

  Private Sub frm_DailySaleSummary_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim cmd As New SqlCommand(" select * from tbl_sales
 where  date between  @dt and @dt1
   and DSR_Name=@Dsr", con)
    Dim da As New SqlDataAdapter(cmd)
    cmd.Parameters.Add("@dt", SqlDbType.Date).Value = uc_Daily_sale.DateTimePicker1.Value
    cmd.Parameters.Add("@dt1", SqlDbType.Date).Value = uc_Daily_sale.DateTimePicker2.Value
    cmd.Parameters.Add("@dsr", SqlDbType.NVarChar).Value = uc_Daily_sale.txt_dsr.Text
    Dim ds As New DataSet
    da.Fill(ds, "item")

    DataGridView1.DataSource = ds.Tables("item")

End Sub

uc_Daily_sale.DateTimePicker1.Value
uc_Daily_sale.DateTimePicker2.Value
uc_Daily_sale.txt_dsr.Text
Shown Error

Developer technologies VB
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2021-11-18T05:59:17.497+00:00

    Hi @jewel ,
    You can bring the value of the Controls in uc_Daily_sale to frm_DailySaleSummary through the constructor of frm_DailySaleSummary
    Here is my code which you can refer to.
    uc_Daily_sale

        Private Sub DataGridView2_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView2.CellDoubleClick  
            Dim frm As New frm_DailySaleSummary(DateTimePicker1.Value, DateTimePicker2.Value, txt_dsr.Text)  
            frm.Show()  
        End Sub  
    

    frm_DailySaleSummary

        Dim DTPicker1 As Date  
        Dim DTPicker2 As Date  
        Dim txt_dsr As String  
        Public Sub New(DTPicker1 As Date, DTPicker2 As Date, txt_dsr As String)  
      
            InitializeComponent()  
            DTPicker1 = DTPicker1  
            DTPicker2 = DTPicker2  
            txt_dsr = txt_dsr  
      
        End Sub  
    

    Hope the code above could be helpful.
    Best Regards.
    Jiachen Li

    ----------

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.