When passing a filter parameter (null and blank checked) to a report in vb.net, I was thinking if the parameter is blank all records would show. It does not. What is the logic behind optional parameters?
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'SkeduleringDatabasisDataSet.Skedulering' table. You can move, or remove it, as needed.
Me.SkeduleringTableAdapter.Fill(Me.SkeduleringDatabasisDataSet.Skedulering)
Dim param1 As New ReportParameter
param1.Name = "ReportParameter1"
param1.Values.Add(Form1.ComboBox1.SelectedValue)
ReportViewer1.LocalReport.ReportPath = "C:\Users\Administrator\Desktop\Trash\WindowsApplication67\WindowsApplication67\Report1.rdlc"
ReportViewer1.LocalReport.SetParameters(New ReportParameter() {param1})
Me.ReportViewer1.RefreshReport()
End Sub
So if I do not make a selection in the combobox (ComboBox1.SelectedIndex = -1) I am expecting the report to show all data?
Related
I am new to VB please assist. I have an application where I search using combo box and two textboxes. Now it is not always when all textboxes have text. Sometimes the user can search using one textbox. My problem is when I leave out a textbox that searches an integer column is using binding source find method I get : 'Input string was not in a correct format.' because the textbox is empty. My database is access database and I am searching from a gridview binding source. How can I allow txtboxIdSize to be ignored if not used? My code below:
Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
TblDiesBindingSource.Filter = $"Descript LIKE '%{txtDescription.Text.Trim()}%'"
TblDiesBindingSource.Position = TblDiesBindingSource.Find("IDSIZE", txtIdSize.Text)
End Sub
Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
If txtboxIdSize.TextLength > 0 then
TblDiesBindingSource.Filter = $"Descript LIKE '%{txtDescription.Text.Trim()}%'"
TblDiesBindingSource.Position = TblDiesBindingSource.Find("IDSIZE", txtIdSize.Text)
End if
End Sub
My datagrid is not formatting the input value.
If I input "5", it returns "5" and not "5,00%"
I tried to change the cellstyle format of the cell in editor to "0,00%" or to "P", but it doesn't format... Already tried "000" or "0,00" and nothing happens... It always returns "5"
If it's any consolation, I couldn't reproduce your complaint:
I set everything up in code, but only because it makes it easier to paste onto SO. Paste this into a form and have a play around with it:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim dt As New DataTable
dt.Columns.Add("Thing", GetType(Double))
dt.Rows.Add(1.234)
dt.Rows.Add(2.345)
Dim dg As New DataGridView
dg.DataSource = dt
Me.Controls.Add(dg) 'so that columns are autogenerated
dg.Columns(0).DefaultCellStyle.Format = "0.00\%"
End Sub
You can do the same in the designer; doesn't have to be code
Add a New DataSet to your project, add a DataTable to it with a decimal capable column (pick better names than I have here):
Open the data sources panel (view menu, other windows), drag the datatable to the form to create a grid, edit the grid's columns to set the format:
and put some data in the underlying table:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.DataSet1.DataTable1.AddDataTable1Row(1.234)
Me.DataSet1.DataTable1.AddDataTable1Row(2.345)
End Sub
I have a button on my form FormA which is called search. When this button is clicked the frmSearch loads. I want to make the frmSearch dynamic so if it called by the button 'Search Employee' it searches only employees etc.
Is there a way which I can input the caller's ID or tag into frmSearch instantly?
This is what I have at the moment but it only identifies the caller control. (I could instantiate a global variable and read it from frmSearch but I'm wondering if there's a better way):
Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
frmSearch.Show()
Dim btn As Button = CType(sender, Button)
MsgBox(btn.ToString)
MsgBox("you have clicked button " & CType(CType(sender, _
System.Windows.Forms.Button).Tag, String))
End Sub
In formA your code will look something like this
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim caller As String = DirectCast(sender, Button).Name
Dim f As New frmSearch(caller)
f.Show()
End Sub
Note that I am not using the default instance of the search form, this is important.
In the search form add this code
Dim whoCalled As String '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Public Sub New(caller As String)
InitializeComponent()
whoCalled = caller
End Sub
The variable whoCalled will contain the name of the caller.
If you want to make it impossible to create the form without passing the data, then in the search form also add
Private Sub New()
' This call is required by the designer.
InitializeComponent()
End Sub
This will force you to use the overloaded constructor.
I'll be more specific. The goal of this is in (Visual Basic) to create a list box with all 50 US states, I am to made a text box with a "TextChanged" action that when the user types in the first couple letters of a state name, it shows that particular state. (For example, typing "Fl" might show Florida). I'm aware of what the SelectedIndex property is, but not really sure how to correctly use it. Thank you.
Assuming a standard ComboBox, you can set
AutoCompleteMode = Append
AutoCompleteSource = ListItems
And make sure you DataSource is set to the list of states. For example, given this code:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim dict As New Dictionary(Of String, String)
With dict
.Add("FL", "Florida")
.Add("NY", "New York")
.Add("AK", "Alaska")
End With
With ComboBox1
.ValueMember = "Key"
.DisplayMember = "Value"
.DataSource = dict.ToList
End With
End Sub
If you type N in the ComboBox, it will suggest New York and this code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MsgBox(ComboBox1.SelectedValue)
End Sub
Will return NY.
I have spent all morning googling and looking through this site and just haven't found anything that seems to work. I have a combobox on form1 that gets its display values from a datasource tblCardTypeDD. Its Display Member is sCardType and its value member is iCardTypeID. Its selected member is fkCardTypeID from tblInventory.
When I click a button form2 pops up with a simple datagridview that allows me to add more card types to be used in the drop down. Currently I have been trying to add code to the save button click method but I just can't find a combination that actually updates the combobox.
I have been trying the following:
frmInventory.SEquipTypeComboBox.DataSource = Nothing
frmInventory.SEquipTypeComboBox.DataSource = Me.EngDBbeDataSet.tblCardTypeDD
but the drop down becomes blank after execution of the above.
Any help would be appreciated.
You should check this page, maybe it'll help you:
http://msdn.microsoft.com/en-us/library/w67sdsex.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
In case it didn't:
if you put your breakpoint where you "reset" The combobox Datasource binding, Check if the datasource contains the new values you want to see in your combobox. it might sound stupid but its a mistake that often happens, if this is the case you know that the problem isn't with the binding
Also after making the datasource nothing and adding the datasource again in the way you did you should tell which column will be the displaymember again like so:
ComboBox1.DisplayMember = "Column1"
Though if you look at the site I told you about you should look at the note that tells you how to suspend and resume binding instead of dropping the datasource and adding it again like that.
Though if you're using a datatable the values should automatically change, and there should be no reason to drop and rebind the combobox.
--
To prove that you don't need to rebind i've very quickly made a very dirty piece of code to prove it.
form1 has a combobox that's bound to a datatable, and it also has a button to call a second form named form2.
form2 has a button that adds 2 rows to the Datatable and then goes back to the first screen.
Code Form 1:
Public Class Form1
Private dataSet As New DataSet("DataSet1")
Private dataTable As DataTable = dataSet.Tables.Add("DataTable1")
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
dataTable.Columns.Add("Column1")
Dim row1 As DataRow = dataTable.NewRow()
row1("Column1") = "Data1"
dataTable.Rows.Add(row1)
Dim row2 As DataRow = dataTable.NewRow()
row2("Column1") = "Data2"
dataTable.Rows.Add(row2)
ComboBox1.DataSource = dataTable
ComboBox1.DisplayMember = "Column1"
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim form2 As New Form2(dataTable)
form2.Show()
End Sub
End Class
Code Form2:
Public Class Form2
Private _dataTable As DataTable
Public Sub New(ByVal dataTable As DataTable)
InitializeComponent()
_dataTable = dataTable
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim row3 As DataRow = _dataTable.NewRow()
row3("Column1") = "Data3"
_dataTable.Rows.Add(row3)
Dim row4 As DataRow = _dataTable.NewRow()
row4("Column1") = "Data4"
_dataTable.Rows.Add(row4)
Me.Close()
End Sub
End Class