how to if condition row hide when condition is false RDLC - rdlc

How to hide row if condition is fale please check below image and please help me this
=IIf(Fields!OrderTypeId.Value = "1", Fields!Orders.Value,0)
=IIf(Fields!OrderTypeId.Value = "2", Fields!Orders.Value,0)
=IIf(Fields!OrderTypeId.Value = "3", Fields!Orders.Value,0)
I want Like This
But when condition is false its show 0

This might be helpful:
=((Fields!OrderTypeId.Value = "3" Or Fields!OrderTypeId.Value = "2" Or
Fields!OrderTypeId.Value = "1")
And (Fields!Orders.Value = 0))
Thanks

Related

How to change picturebox from visible to not visible if label with a certain number appears?

Good morning,
I'm creating a Stock software and I create two circles, one red and one yellow that I am using on a Picture box. I want that when the stock of label x is = or > 5 that picture box 1 appear on my dashboard. When label x is between 6 - 10 the yellow one appears and none of them appear if the value of label x is bigger than 10.
I tried to type different codes but none of them work correctly.
My code right now is:
If StockDrillbits.GreenSquareQty.Text Or
StockDrillbits.RedSquareQty.Text Or
StockDrillbits.BlackSquareQty.Text Or
StockDrillbits.GreenStarQty.Text Or
StockDrillbits.RedStarQty.Text Or
StockDrillbits.BlackStarQty.Text = "5" Or "4" Or "3" Or "2" Or "1" Or "0" Then
LowStockDrillbits.Visible = True
MediumStockDrillbits.Visible = False
ElseIf StockDrillbits.GreenSquareQty.Text Or
StockDrillbits.RedSquareQty.Text Or
StockDrillbits.BlackSquareQty.Text Or
StockDrillbits.GreenStarQty.Text Or
StockDrillbits.RedStarQty.Text Or
StockDrillbits.BlackStarQty.Text = "10" Or "9" Or "8" Or "7" Or "6" Then
MediumStockDrillbits.Visible = True
LowStockDrillbits.Visible = False
Else
LowStockDrillbits.Visible = False
MediumStockDrillbits.Visible = False
End If
I can't think any other way of doing this. I tried to convert any of the labels to int32, tried to create variables as integer and as single. Everything else on the software is working amazing but this simple code is not.
Anyone could help me? Code is Visual Basic.
You have a common syntax mistake in your code. While the If statement makes sense in English, you are thoroughly confusing VB. As mentioned in my comment, you cannot say:
Text = "4" Or "5"
But instead you need to say:
Text = "4" Or Text = "5"
Applying this idea to your code, with a couple of enhancements, you end up with:
If Val(StockDrillbits.GreenSquareQty.Text) <= 5 Or Val(StockDrillbits.RedSquareQty.Text) <= 5 Or Val(StockDrillbits.BlackSquareQty.Text) <= 5 Or Val(StockDrillbits.GreenStarQty.Text) <= 5 Or Val(StockDrillbits.RedStarQty.Text) <= 5 Or Val(StockDrillbits.BlackStarQty.Text) <= 5 Then
LowStockDrillbits.Visible = True
MediumStockDrillbits.Visible = False
ElseIf Val(StockDrillbits.GreenSquareQty.Text) <= 10 Or Val(StockDrillbits.RedSquareQty.Text) <= 10 Or Val(StockDrillbits.BlackSquareQty.Text) <= 10 Or Val(StockDrillbits.GreenStarQty.Text) <= 10 Or Val(StockDrillbits.RedStarQty.Text) <= 10 Or Val(StockDrillbits.BlackStarQty.Text) <= 10 Then
LowStockDrillbits.Visible = False
MediumStockDrillbits.Visible = True
Else
LowStockDrillbits.Visible = False
MediumStockDrillbits.Visible = False
End If
I shortened the code somewhat by using <= instead of a hard-coded range of numbers. Also, I applied Val to the Text so you are actually comparing numbers instead of strings. If you like, Val can be replaced with, for instance, CType.
Add the values to be compared to arrays, this makes the comparison code more compact.
Dim lowLables As String() = {"0", "1", "2", "3", "4", "5"}
Dim highLables As String() = {"6", "7", "8", "9", "10"}
Dim quantities As String() = {
StockDrillbits.GreenSquareQty.Text,
StockDrillbits.RedSquareQty.Text,
StockDrillbits.BlackSquareQty.Text,
StockDrillbits.GreenStarQty.Text,
StockDrillbits.RedStarQty.Text,
StockDrillbits.BlackStarQty.Text }
LowStockDrillbits.Visible = quantities.Any(Function(q) lowLables.Contains(q))
MediumStockDrillbits.Visible = quantities.Any(Function(q) highLables.Contains(q))
My code uses LINQ Method Syntax. First, it creates 2 arrays containig the labels "0" to "5" and "6" to "10". Then it creates an array named quantities containing the text of the StockDrillbits textboxes or labels.
quantities.Any(...) contains a condition that must be True for any of the quantity strings. The condition is given as a Lambda Expression. The condition lambda Function(q) lowLables.Contains(q) tests whether a quantity string is contained in the lowLables array. The same is then done for the highLables array.
I also replaced the lengthy If-statement by direct assignment of the condition results to the picture boxes.

creating a loop around my select Case

At present, I have a functioning Select Case that states that if a textbox is blank then it is to be highlighted red, but it only seems to be highlighting one of the textboxes. For instance, if 2 textboxes are left blank, it only highlights the first on it comes across.
Select Case True
Case Me.CustName = ""
Me.CustName.BackColor = &H8080FF
Case Me.RegAddress = ""
Me.RegAddress.BackColor = &H8080FF
Case Me.PostInput = ""
Me.PostInput.BackColor = &H8080FF
Case Me.Landline = ""
Me.Landline.BackColor = &H8080FF
Case Me.Contact = ""
Me.Contact.BackColor = &H8080FF
Case Me.DOBInput = ""
Me.DOBInput.BackColor = &H8080FF
End Select
Being new to VBA, my only thinking is to create a loop round my current code that state (loop until x,y or z is <> "") but I can't seem to figure out how to do this.
Any advice will be greatly appreciated.
Select Case runs the code block following the first matching Case statement only. If you need to check each of your conditions regardless, you should write them as individual If statements instead:
If Me.CustName = "" Then Me.CustName.BackColor = &H8080FF
If Me.RegAddress = "" Then Me.RegAddress.BackColor = &H8080FF
If Me.PostInput = "" Then Me.PostInput.BackColor = &H8080FF
....
You are using Select Case for the wrong purpose. Its purpose is to test a single expression and execute one branch based on the value of that expression.
What you need to do is test each of your text boxes individually, using if statements:
If Me.CustName = "" Then Me.CustName.BackColor = &H8080FF
'etc.

Simple Random generator generates blank item

I am creating a random generator of text.
It works ok but a small issue that I can't seem to resolve is occurring.
When I click my test button, every now and then a blank item appears. Here is my code.
Dim rng As New System.Random()
Dim RAND(16) As String
RAND(0) = "A"
RAND(1) = "B"
RAND(2) = "C"
RAND(3) = "D"
RAND(4) = "E"
RAND(5) = "F"
RAND(6) = "G"
RAND(7) = "H"
RAND(8) = "I"
RAND(9) = "J"
RAND(10) = "K"
RAND(11) = "L"
RAND(12) = "M"
RAND(13) = "N"
RAND(14) = "O"
RAND(15) = "P"
TextBox1.Text = RAND(rng.Next(RAND.Count()))
Your RAND(16) as declared contains 17 elements. Last one is blank, because you did not initialize it to anything. You can use a Watch window to verify:
Regarding how Nothing becomes a blank, it's a result of an implicit conversion behind the scenes.

How to check multiple conditions in rdlc expression

I have worked on only possible 2 in rdlc Expression values as like
=iif((Fields!Gender.Value="1"),"Male","Female")
Here I can work with only 2 possibilities. But if I want to check 3 or more conditions than how can I?
Use the Switch if you have more conditions, it is also more readable.
=Switch(
Fields!Gender.Value = 1, "Male",
Fields!Gender.Value = 2, "Female"
)
rdlc expression iif use?
You can use the Code property of the report. Right-click a blank space outside your report and click Report Properties or click the Report menu and click report properties.
Click the "Code" tab and type your condition checking statement as below
Public Function GetGender(ByVal val as String) As String
Dim retVal as String = ""
If(val = "1")
retVal = "Male"
Else If (val = "2")
retVal = "???"
Else If (val = "3")
retVal = "???"
Else
retVal = "???"
End If
Return retVal
End Function
Then call the function in the expression of your textbox
= Code.GetGender(Fields!Gender.Value)
try this one :
=iif(Fields!Gender.Value="1","Male", iif(Fields!Gender.Value="2","Female","Undefined"))
the format is :
=iif(expression=value, true, false)
you can change with :
=iif(expression=value, true, iif(expression2=value2, true, false))
Switch and Custom Code look's nice, Thank you Guys
But if you insist using iif() condition then,
=iif( (Fields!Gender.Value="1"), "Male", iif( (Fields!Gender.Value="2"), "Female", "Something Else" ) )
Ok, Bye

DataGridView column order does not seem to work

I have a DataGridView bound to a list of business objects:
Dim template As New IncidentTemplate
Dim temps As List(Of IncidentTemplate) = template.LoadAll
Dim bs As New BindingSource
If Not temps Is Nothing Then
bs.DataSource = temps
Me.dgvTemplates.DataSource = bs
End If
I then add an unbound button column and make some of the bound columns invisible:
Dim BtnCol As New DataGridViewButtonColumn
With BtnCol
.Name = "Edit"
.Text = "Edit"
.HeaderText = String.Empty
.ToolTipText = "Edit this Template"
.UseColumnTextForButtonValue = True
End With
.Columns.Add(BtnCol)
BtnCol = Nothing
For Each col As DataGridViewColumn In Me.dgvTemplates.Columns
Select Case col.Name
Case "Name"
col.DisplayIndex = 0
col.FillWeight = 100
col.Visible = True
Case "Description"
col.DisplayIndex = 1
col.FillWeight = 100
col.Visible = True
Case "Created"
col.DisplayIndex = 3
col.HeaderText = "Created On"
col.DefaultCellStyle.Format = "d"
col.FillWeight = 75
col.Visible = True
Case "CreatedBy"
col.DisplayIndex = 2
col.HeaderText = "Created By"
col.FillWeight = 75
col.Visible = True
Case "Edit"
col.DisplayIndex = 4
col.HeaderText = ""
col.FillWeight = 30
col.Visible = True
Case Else
col.Visible = False
End Select
Next
This seems to work reasonably well except no matter what I do the button column (Edit) always displays in the middle of the other columns instead of at the end. I've tried both DGV.Columns.Add and DGV.Columns.Insert as well as setting the DisplayIndex of the column (this works for all other columns) but I am unable to make the button column display in the correct location. I've also tried adding the button column both before and after setting the rest of the columns but this seems to make no difference Can anyone suggest what I am doing wrong? It's driving me crazy....
I stumbled on your post while looking to solve a similar problem. I finally tracked it down by doing as you mention (using the DisplayIndex property) and setting the AutoGenerateColumns property of the DataGridView to false. This property is not visible in the designer, so I just added it to the constructor for my form. Be sure to do this before setting the data source for your grid.
Hope this helps...
The AutoCreateColumn is the problem. The following article gives an example for how to fix it.
From DataDridView DisplayOrder Not Working
When setting the column’s DisplayIndex in a data grid view, some columns were out of order. To fix the issue, I had to set AutoGenerateColumns to true before setting the data source, and to FALSE after.
For Example:
dgvReservedStalls.AutoGenerateColumns = True
dgvReservedStalls.DataSource = clsReservedStalls.LoadDataTable()
dgvReservedStalls.AutoGenerateColumns = False
Same problem here, and after searching for a while, I found out that by setting the DisplayIndexes in Ascending order made it for me.
It's counter-intuitive, because it's a number, but I still had to set them in order.
This works:
With customersDataGridView
.Columns("ContactName").DisplayIndex = 0
.Columns("ContactTitle").DisplayIndex = 1
.Columns("City").DisplayIndex = 2
.Columns("Country").DisplayIndex = 3
.Columns("CompanyName").DisplayIndex = 4
End With
While this did not:
With customersDataGridView
.Columns("ContactName").DisplayIndex = 0
.Columns("CompanyName").DisplayIndex = 4
.Columns("Country").DisplayIndex = 3
.Columns("ContactTitle").DisplayIndex = 1
.Columns("City").DisplayIndex = 2
End With
I tried the above solutions without success. Then I found this article: It made it all better.
http://msdn.microsoft.com/en-us/library/vstudio/wkfe535h(v=vs.100).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1