I am using VB.Net 2013 with SQL Server
What is the problem with my code? Is there something missing?
When I try to select the location, it show me in the Form the name, location and the image.
Everything looks good, the only problem is that the image in report viewer doesn't change.
Imports System.IO
Imports Microsoft.Reporting.WinForms
Public Class Form1
Private Sub Table_locationBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles Table_locationBindingNavigatorSaveItem.Click
Me.Validate()
Me.Table_locationBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.KankonDataSet)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'KankonDataSet.Table_location' table. You can move, or remove it, as needed.
Me.Table_locationTableAdapter.Fill(Me.KankonDataSet.Table_location)
If NamelocationComboBox.Text = Nothing Then
NamelocationComboBox.Text = "No thing"
End If
If IdlocationTextBox.Text = Nothing Then
IdlocationTextBox.Text = "No thing"
End If
Dim Param1 As New ReportParameter("ReportParameterlocation", NamelocationComboBox.Text)
ReportViewer1.LocalReport.SetParameters(Param1)
Dim Param2 As New ReportParameter("ReportParameterwhere", IdlocationTextBox.Text)
ReportViewer1.LocalReport.SetParameters(Param2)
Me.ReportViewer1.RefreshReport()
End Sub
Private Sub ReportViewer1_Load(sender As Object, e As EventArgs) Handles ReportViewer1.Load
Me.ReportViewer1.RefreshReport()
End Sub
Private Sub NamelocationComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles NamelocationComboBox.SelectedIndexChanged
Dim Param1 As New ReportParameter("ReportParameterlocation", NamelocationComboBox.Text)
ReportViewer1.LocalReport.SetParameters(Param1)
Me.ReportViewer1.RefreshReport()
End Sub
Private Sub IdlocationTextBox_TextChanged(sender As Object, e As EventArgs) Handles IdlocationTextBox.TextChanged
Dim Param2 As New ReportParameter("ReportParameterwhere", IdlocationTextBox.Text)
ReportViewer1.LocalReport.SetParameters(Param2)
Me.ReportViewer1.RefreshReport()
End Sub
End Class
Image in Attachments!
Related
in the first form I have a text box where you can add your name, and then when you click Next window, the second form will pop up saying My name is : Your name . This is great, but how would I be able to change the name of the second form known as OtherForm to my name aswell so that when the second form pops up, on the top left corner my name would appear instead of OtherForm? Here is the code for the first and second form so far.
Main Form code:
Public Class MainForm
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
End Sub
Public Sub Label1_Click(sender As Object, e As EventArgs) Handles
WindowName.TextChanged
End Sub
Public Sub WindowName_TextChanged(sender As Object, e As EventArgs)
End Sub
Public Sub OffButton_Click(sender As Object, e As EventArgs) Handles
OffButton.Click
Me.Close()
End Sub
Public Sub NextButton_Click(sender As Object, e As EventArgs) Handles
NextButton.Click
OtherForm.NameLabel.Text = WindowName.Text
OtherForm.Show()
End Sub
End Class
Second form known as OtherForm
Public Class OtherForm
Public Sub CloseButton_Click(sender As Object, e As EventArgs) Handles
CloseButton.Click
Me.Close()
End Sub
Public Sub OtherForm_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
End Sub
Public Sub NameLabel_Click(sender As Object, e As EventArgs) Handles
NameLabel.Click
End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles
Label1.Click
End Sub
End Class
Try
OtherForm.Text = WindowName.Text
to set the title of the form. Or you can set the text to whatever you would like. I'm not sure if you mean "my name" or the name you entered.
If you do mean "my name" then you can enter that in the form property for "Text" instead of in code as well.
I'm trying to make a little prank program where a form keeps opening until it hits a certain number like 50 or something, I've tried this:
Public Class Form2
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Show()
End Sub
End Class
But that doesn't work, anyone willing to help? Thanks
Ditto what litelite said. If you want to show a new instance of the form, Show() won't cut it.
In fact, once you close that form, the timer you're using will be lost. So you'll need to handle the Form.Closing event as well. Since we're just having fun here, I'd suggest that you make that work like cutting off the head of a Hydra, two more replace it.
Try something like this:
Public Class Form2
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim _newForm as Form2 = new Form2()
_newForm.Show()
End Sub
Private Sub Me_Closing(sender As Object, e As EventArgs) Handles Form2.Closing
Dim _newForm as Form2 = new Form2()
_newForm.Show()
Dim _newForm2 as Form2 = new Form2()
_newForm2.Show()
End Sub
End Class
I have a webform for entering Invoice info to a DB.
I have 3 textboxes requesting product quantity, product and price.
I decided to create a DataTable to store temporarily quantity, productId, price so that the user might add N products for later saving the data on the DataTable (displayed on a grid) to the DB.
I don't know what am I doing wrong but am unable to store a second product. After I save 1 row to the DataTable the second one is not added but overwrites the first one. I know this has to be something really stupid on my part but haven´t been able to figure out what am I doing wrong and am sort of a beginner.
Public Class IngresoFacturas
Inherits System.Web.UI.Page
Dim miDataTable = New DataTable
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
miDataTable.Columns.Add("dCantidad", GetType(System.Int32))
miDataTable.Columns.Add("idProducto", GetType(System.Int32))
miDataTable.Columns.Add("mTotal", GetType(System.Decimal))
End Sub
Protected Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
miDataTable.Rows.Add(RadNumericTextBox2.Text, Int32.Parse(RadAutoCompleteBox2.Entries.Item(0).Value), RadNumericTextBox3.Text)
RadGrid1.Rebind() 'Forces rebind to update Grid
RadAutoCompleteBox2.Entries.Clear()
RadNumericTextBox2.Text = ""
RadNumericTextBox3.Text = ""
End Sub
Protected Sub RadGrid1_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
RadGrid1.DataSource = miDataTable
End Sub
End Class
Tried Andrew´s solution but it didn{t work so I came up to this:
Anything you guys could warn me about using ViewState to solve this. It is working.... but don{t know if it{s the best approach
Public Class IngresoFacturas
Inherits System.Web.UI.Page
Dim miDataTable As DataTable
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
miDataTable = New DataTable
miDataTable.Columns.Add("dCantidad", GetType(System.Int32))
miDataTable.Columns.Add("idProducto", GetType(System.Int32))
miDataTable.Columns.Add("mTotal", GetType(System.Decimal))
ViewState("tabla") = miDataTable
End If
End Sub
Protected Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
miDataTable = ViewState("tabla")
miDataTable.Rows.Add(RadNumericTextBox2.Text, Int32.Parse(RadAutoCompleteBox2.Entries.Item(0).Value), RadNumericTextBox3.Text)
RadGrid1.Rebind() 'Forces rebind to update Grid
ViewState("tabla") = miDataTable
RadAutoCompleteBox2.Entries.Clear()
RadNumericTextBox2.Text = ""
RadNumericTextBox3.Text = ""
End Sub
Protected Sub RadGrid1_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
RadGrid1.DataSource = miDataTable
End Sub
End Class
Something like this might help:
Dim miDataTable As DataTable
Sub PrepareDT()
miDataTable = New DataTable
miDataTable.Columns.Add("dCantidad", GetType(System.Int32))
miDataTable.Columns.Add("idProducto", GetType(System.Int32))
miDataTable.Columns.Add("mTotal", GetType(System.Decimal))
End Sub
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
If Not Page.IsPostBack Then
PrepareDT()
End If
End Sub
(and remove the code from the Page_Load method) so that you only "reset" miDataTable on the first access of the page.
I'm very frustrated trying to get my code to work.
I'm trying to have a selected item in a listbox removed also in the textbox.
Getting ready to remove text;
Removed the text;
But it's still in the textbox.
Here is my code
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ListBox1.Items.Add(TextBox1.Text)
TextBox2.Text += TextBox1.Text & vbNewLine
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
ListBox1.Items.Remove(ListBox1.SelectedItem)
'
'//HOW TO REMOVE THE SELECTED TEXT IN THE LISTBOX ALSO REMOVED IN THE TEXTBOX2??
'
'
End Sub
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Dim filenames As String = "C:\log\log.txt"
My.Computer.FileSystem.WriteAllText(filenames, TextBox2.Text, False)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim filenames As String = "C:\log\log.txt"
If My.Computer.FileSystem.FileExists(filenames) Then
TextBox2.Text = My.Computer.FileSystem.ReadAllText(filenames)
Dim items()
items = TextBox2.Lines()
For Each item In items
ListBox1.Items.Add(item)
Next
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Clipboard.SetText(ListBox1.SelectedItem)
End Sub
End Class
The worst part is that every time I try to look it up online, there are no errors until I click the button that says 'Value Cannot Be Null'
It happened every single time.
Please, before you mash the -1 button, at least tell me why. I'm new to this.
This should work for you
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Text = TextBox1.Text.Replace(ListBox1.Items(ListBox1.SelectedIndex), Nothing)
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
End Sub
End Class
I have two forms, the main (Main.vb) program window and a pop-up that appears when the program is started (getInitialBalance.vb). I need to get a value entered into the PopUp window from the popup window to the Main program. The relevant code is shown below:
getinitialbalance.vb
Public Class GetInitialBalance
Public initialBalance As Integer
Private Sub btnApplyInitialBal_Click(sender As Object, e As EventArgs) Handles btnApplyInitialBal.Click
Dim textinput As Integer = txtInitialBalance.Text
initialBalance = textinput
Me.Close()
End Sub
End Class
Main.vb
Public Class Main
Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
GetInitialBalance.ShowDialog()
End Sub
Dim localInitialBalance As Integer = GetInitialBalance.initialBalance
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MsgBox(localInitialBalance)
End Sub
End Class
New up the GetInitialBalance form and then when the user clicks OK on the popup dialog, grab the value initialBalance from the reference to GetInitialBalance, like this:
Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim popup As New GetInitialBalance
If popup.ShowDialog = Windows.Forms.DialogResult.OK Then
localInitialBalance = popup.initialBalance
End If
End Sub
Your entire code should look like this:
Public Class GetInitialBalance
Public initialBalance As Integer
Private Sub btnApplyInitialBal_Click(sender As Object, e As EventArgs) Handles btnApplyInitialBal.Click
initialBalance = Convert.ToInt32(textinput)
Me.DialogResult = Windows.Forms.DialogResult.OK
End Sub
End Class
Public Class Main
Dim localInitialBalance As Integer
Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim popup As New GetInitialBalance
If popup.ShowDialog = Windows.Forms.DialogResult.OK Then
localInitialBalance = popup.initialBalance
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MsgBox(localInitialBalance)
End Sub
End Class