I'd like to create a list box in vb.net that lists the item whenever the user clicks the button it updates information, my variables are a string and an integer concatenated, the problem is that when the user clicks on the button the item doesn't remove on the list
I've tried converting the integer variable to string and it still doesn't work
Private Sub btnAddChicken_Click(sender As Object, e As EventArgs) Handles btnAddChicken.Click
If cmbChicken.SelectedIndex = 0 Then
'''qfried is the quantity
'''tfried is the total amount
'''tfried and qfried are the variable i want to update
qfried = qfried + 1
tfried = tfried + pfried
If ListAllOrders.Items.Contains("Fried Chicken - P" & Convert.ToString(tfried) & " Quantity (" & Convert.ToString(qfried) & ")") Then
ListAllOrders.Items.Remove("Fried Chicken - P" & Convert.ToString(tfried) & " Quantity (" & Convert.ToString(qfried) & ")")
ListAllOrders.Items.Add("Fried Chicken - P" & tfried & " Quantity - (" & qfried & ")")
i += 1
Else
ListAllOrders.Items.Add("Fried Chicken - P" & tfried & " Quantity - (" & qfried & ")")
End If
End If
End Sub
I expect that the information would be updated
The remove option of the ListBox does not work with Strings, but with ListBoxItems. For you to remove it, you can do it like this:
For Each item In ListAllOrders.Items
If item.Contains(desiredStringToRemove) Then
ListAllOrders.Items.Remove(item)
Exit for
End If
Next
Related
The input changes to $0.00 whenever i try this coding:
Private Sub btnEnt_Click(sender As Object, e As EventArgs) Handles btnEnt.Click
Dim result As String
Dim earn As Decimal
txtEarning.Text = earn.ToString("C")
result = txtFName.Text & " " & txtLName.Text & " Worked" & vbCrLf
result &= nudHr.Value & " Hrs today"
result &= " and his earning is " & txtEarning.Text
txtRes.Text = result
End Sub
instead of displaying input value, the value automatically converts to $0.00
I think you might need this:
Dim earn as Decimal = nudHr.Value * 20
If your person earns 20 dollars an hour
I have been googling and searching youtube but find no answer, so I would like to ask for help in here.
I want to group the name in the TreeView control in VB, how can I do it?
Thank you
Public Class FrmPengingat
Private Sub FrmPengingat_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DSLap.PengingatHutang' table. You can move, or remove it, as needed.
Me.PengingatHutangTableAdapter.Fill(Me.DSLap.PengingatHutang)
'fill the tree control
Dim NmPemasok As String
Dim NoNota As String
Dim TglJatuhTempo As Date
Dim Total As Decimal
Dim tmpNmPemasok As String
Dim i As Integer
For i = 0 To DSLap.PengingatHutang.Count - 1
NmPemasok = DSLap.PengingatHutang.Rows(i).Item(0)
tmpNmPemasok = DSLap.PengingatHutang.Rows(i).Item(0)
NoNota = DSLap.PengingatHutang.Rows(i).Item(1)
TglJatuhTempo = DSLap.PengingatHutang.Rows(i).Item(2)
Total = DSLap.PengingatHutang.Rows(i).Item(3)
TreeView1.Nodes.Add(i, NmPemasok).Nodes.Add(i, NoNota & " (" & TglJatuhTempo & ") " & Total)
Next
End Sub
End Class
This line:
TreeView1.Nodes.Add(i, NmPemasok).Nodes.Add(i, NoNota & " (" & TglJatuhTempo & ") " & Total)
adds a new parent node every time. You should check if the tree view already contains a node with the same text and only add a new one if it doesn't.
I suggest you make the key the same as the text for the parent node, that way it'll be easier to check if it exists or not.
Replace the above with this:
If TreeView1.Nodes.ContainsKey(NmPemasok) Then 'The parent node already exists.
TreeView1.Nodes(NmPemasok).Nodes.Add(i, NoNota & " (" & TglJatuhTempo & ") " & Total)
Else 'The parent node doesn't exist.
TreeView1.Nodes.Add(NmPemasok, NmPemasok).Nodes.Add(i, NoNota & " (" & TglJatuhTempo & ") " & Total)
End If
Need to display [Feature] - [FeatureStatus] - [FeaturePerComplete]% if feature field has value or else need to display N/A, what expreession do I need to give for this
Try changing
=IIf(Fields!Feature.Value Is Nothing, "N/A",Fields!Feature.Value & " - " & Fields!FeatureStatus.Value & " - " & Fields!FeaturePerComplete.Value & "%")
to..
=IIf(Isnothing(Fields!Feature.Value), "N/A",Fields!Feature.Value & " - " & Fields!FeatureStatus.Value & " - " & Fields!FeaturePerComplete.Value & "%")
This relies on the Feature column being null in those circumstances - will it definitely be null, or will it be blank?
So Basically in this Program I need to add multiple records under the same Material Request ID (PRID). When I insert all the data and when I press submit it will ask to add another product or not .
So when I click yes to add another product the previous records should be added to the table (tblProductRequest) as well as to add the new records the combo boxes and the txt boxes should also be cleared.
I have cleared out how to do the clearing of data in the text boxes and the combo boxes but in the next time when I press submit it should save the record under the same Material Request ID and it should go on like that.
I don't know how to insert a loop to continue the procedure of keep adding items to the table under the same Material Request ID (PRID)
Product Name Combo Box = "cmbProductName"
Product ID Combo Box = "cmbProductID"
Quantity Purchased = "txtQTYPurchase"
Dim rsProduceMRN As New ADODB.Recordset
rsProduceMRN.Open "select * from tblProductRequest where PRID = '" & txtPRID & "' ", CurrentProject.Connection
If rsProduceMRN.EOF Then
CurrentProject.Connection.Execute "Insert into tblProductRequest(PRID, ProductID, QtyReq,DateRequested) values " _
& " ('" & txtPRID & "', '" & cmbProductID & "'," & txtQTYPurchase & ", #" & txtDOP & "#) "
res = MsgBox("Product Addeded to the MRN. Do you want to add a New Product?", vbYesNo, "Save Record")
If res = vbYes Then
cmbProductID = ""
txtQTYPurchase = ""
cmbProductName = ""
Else
DoCmd.Close
DoCmd.OpenReport "rptMRN", acViewPreview
End If
End If
End Sub
i have a problem in viewing items in listview
this is my code
rs.Open("select tableStudentRecords.*, tableTransaction.*, tablePayments.* from tableStudentRecords, tableTransaction , tablePayments" & _
" where tableStudentRecords.studnum = tableTransaction.studnum and tablePayments.psitscode = tableTransaction.psitscode", con, 3, 3)
Dim i As Integer = 0
With lvPaymentRecords
Do Until rec.EOF
.Items.Add(rec("tableTransaction.studnum").Value)
x = rec("sname").Value & ", " & rec("fname").Value & " " & rec("mi").Value & " " & rec("ext").Value
.Items(i).SubItems.Add(x)
lvPaymentRecords.Items(i).SubItems.Add(rec("sem").Value)
.Items(i).SubItems.Add(rec("sy").Value)
.Items(i).SubItems.Add(rec("total").Value)
i = i + 1
rec.MoveNext()
Loop
End With
rec.Close()
con.Close()
the thing is, items wont appear in listview, i dont know what is the cause,
tableStudentRecords and tablePayments are both PRIMARY keys,
here is the database relationships
(im sorry i cant post the image due to less reputation)
tableStudentRecords _____ tableTransaction _____ tablePAyments
-studnum _____________ -psitscode _____________-psitscode
-sname _______________ -studnum ____________-sem
-fname ________________ -sy __________________-payname
-gndr __________________-total _______________-amount
i only need to view the sem from tablePayments in listview load,
You must declare a ListViewItem variable. The codes should be
Dim lpRec As ListViewItem
With lvPaymentRecords
Do Until rec.EOF
lpRec=.Items.Add(rec("tableTransaction.studnum").Value)
x = rec("sname").Value & ", " & rec("fname").Value & " " & rec("mi").Value & " " & rec("ext").Value
lpRec.SubItems.Add(x)
lpRec.SubItems.Add(rec("sem").Value)
lpRec.Items(i).SubItems.Add(rec("sy").Value)
lpRec.Items(i).SubItems.Add(rec("total").Value)
i = i + 1
rec.MoveNext()
Loop
End With
rec.Close()
con.Close()
Hope it can help you.