How can I create a TableLayoutPanel in VB Dynamically? - vb.net

I'm trying to make a tableLayoutPanel by code in Windows Form VB which can later be coded to add on extra rows and columns also by coding

When the form starts:
Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _MyBase.Load
Dim TLP As New TableLayoutPanel
'Edit all your properties: name, size, location, etc.
End Sub
Say when you click a button1:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Controls.Add(TLP)
End Sub
Hope that helps.

Related

Open different forms on different button click in VB.NET

A noob query I have, is there any way to use a single command to open different forms on different button click events. I have 24 buttons in one form and will use these buttons to open 24 different forms.
So instead of doing it for 24 times as:
Private Sub BtnCh1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCh1.Click
FormCh1.Show()
End Sub
Private Sub BtnCh2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCh2.Click
FormCh2.Show()
End Sub
Private Sub BtnCh3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCh3.Click
FormCh3.Show()
End Sub
Private Sub BtnCh4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCh4.Click
FormCh4.Show()
End Sub
Can it be done with a single command?
In your form's load event add the forms in a List(Of Form)
Private list As List(Of Form)
Private Sub Me_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
list = New List(Of Form)
list.Add(New Form1())
'
'
'
list.Add(New Form24())
End Sub
Set your button's Tag property with the form's index and set them all to use the same click event:
Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn.Click
list(CType(sender, Button).Tag).Show()
End Sub
Attach all the handlers to your method and then branch behaviour based on the Select Case:
Private Sub Button_Click_Handler(sender As Object, e As EventArgs) Handles Button66.Click, Button67.Click, Button68.Click
Dim btn As Button = DirectCast(sender, Button)
Select Case btn.Name
Case Button66.Name
Dim f1 As New Form1
f1.Show()
Case Button67.Name
Dim f2 As New Form2
f2.Show()
Case Button68.Name
Dim f3 As New Form3
f3.Show()
End Select
End Sub

how do i save time in datagridview in vb.net 2010 [Newbie student]

Example i press start time and the time connected in textbox that it will show when i start the time same with out time,and when i press save it wont add to datagridview. Please help me with my problem. This is my save code:
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Table1BindingSource.AddNew()
Me.Validate()
Me.Table1BindingSource.EndEdit()
Me.Table1TableAdapter.Update(Me.OpenDataSet.Table1)
End Sub
Ok, I solved your problem....
Here is how your form should look like :
And now you need to add the "Time" columns to the datagridview:
And now... follow my steps through the image:
and here is the code :
Public Class Form1
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Table1BindingSource.Rows.Add()
Table1BindingSource.Rows(Table1BindingSource.Rows.Count - 1).Cells(0).Value = TextBox1.Text & Table1BindingSource.Rows.Count
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CountTimer.Tick
TextBox1.Text += 1
End Sub
End Class
I Hope My Answer Was Useful To You :)

vb2010 pass data from one form to another

I am trying to pass a value of a textbox on frmMain to a textbox on frmDepartment. I have tried the following code which I thought would work but it dosen't. I ma a new user to VB and come from a php background where it would have been a simple task of setting a seesion. Can anyone help with this? If you need to see more code, please ask. many thanks
txtDeptCustomer.Text = frmMain.txtCustomerActive.Text
In frmMain, I am getting value like this:
Dim value As Object = UserDataGridView.Rows(e.RowIndex).Cells(0).Value
txtCustomerActive.Text = CType(value, String)
Private Sub btnDepts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDepts.Click
frmDepartment.Show()
End Sub
Which is showing in frmMain ok.
In frmDepartment I have this code
Private Sub txtDeptCustomer_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDeptCustomer.TextChanged
'Dim customer As String
txtDeptCustomer.Text = frmMain.txtCustomerActive.Text
End Sub
instead of putting the code within the txtDeptCustomer.TextChanged sub, try putting it within the frmDepartment_load:
Private Sub frmDepartment_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
txtDeptCustomer.Text = frmMain.txtCustomerActive.Text
End Sub
or you could set the frmDepartment text box text on the frmMain button click:
Private Sub btnDepts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDepts.Click
frmDepartment.txtDeptCustomer.Text = txtCustomerActive.Text
frmDepartment.Show()
End Sub

vb.net RDLC report doesn't show report when button is clicked

In my Vb.net application I use rdlc report and ReportViewer. But it only loads report in the page_load event.
Here is my code
Private Sub report_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.displayTableAdapter.Fill(Me.aludbDataSet.display)
Me.ReportViewer1.RefreshReport()
End Sub
When I change it to Button_click event, it doesn't load the report. Code is here
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.displayTableAdapter.Fill(Me.aludbDataSet.display)
Me.ReportViewer1.RefreshReport()
End Sub
I don't know why this happened. Because both are same code, only the way is different. Now, I want to load the report when the button is clicked. How to do that? Anyone help please. Thanks
try adding the "Handles" code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Manipulating Controls On Parent Forms From Child VB.NET

I'm trying to add a new row to a DataGridView from FORM 2 but I can not succeed, the code I tried is as follows:
FORM 2:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FORM1.invoice_items.Rows.Add()
End Sub
Looking like it took time but can not find a solution, someone who can help me with my problem would be nice, Thank You.
Try this
This work only if you use a showdialog.
Form 2 :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Pass the value to be added in the datagrid to form 1
Me.DialogResult=Windows.Forms.DialogResult.OK
End Sub
Form 1:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Form2.ShowDialog = Windows.Forms.DialogResult.OK Then
'Getthe value from form 2
invoice_items.Rows.Add()
End If
End Sub