read single word from listbox vb - vb.net

I have an order form I created in VB.NET and I have a ListBox that is populated by order. You can double click on the order and it populates the order number in the order form. The problem I'm having is that it populates the TextBox with both the order number and the persons name. How can I use a delimiter to only pull out the order number and not the name also.
Imports Business_Objects
Public Class frmSummary
Private ctrl As Controller
Dim listID As ArrayList
Private Sub frmSummary_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ctrl = CType(MdiParent, frmMain).ctrl
Dim list As ArrayList
list = ctrl.GetOrders
Dim order As Business_Objects.Order
For Each order In list
lstOrders.Items.Add(order.ID & "," & " " & order.Server)
Next
End Sub
Private Sub lstOrders_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstOrders.DoubleClick
Dim result As Boolean = False
If lstOrders.Text <> "" Then
result = True
Dim frm As New OrderForm
frm.MdiParent = Me.MdiParent
frm.Show()
frm.txtOrderNo.Text = lstOrders.Text
frm.btnFetch.PerformClick()
Else
MessageBox.Show("there are no orders here to click")
End If
End Sub
Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
lstOrders.Items.Clear()
ctrl = CType(MdiParent, frmMain).ctrl
Dim list As ArrayList
list = ctrl.GetOrders
Dim order As Business_Objects.Order
For Each order In list
lstOrders.Items.Add(order.ID & " " & order.Server)
Next
End Sub
End Class

If all of your data is being stored as a single field, or something like:
4322305 John Smith Carrots $3.00
845825 Sam White Oranges $1.25
Then you can read each record as a string, and then use split that into an array based on " " as your delimiter.
The code would look something like:
dim myArray as string() = myLongTextRecord.Split(" ")
And in that format,
textBoxName.Text = myArray[1]

You're almost there. You could use the split function, but another approach would be to add the Order object directly to the listbox and not text.
Private Sub frmSummary_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ctrl = CType(MdiParent, frmMain).ctrl
Dim list As ArrayList
list = ctrl.GetOrders
Dim order As Business_Objects.Order
For Each order In list
lstOrders.Items.Add(order)
Next
End Sub
Private Sub lstOrders_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstOrders.DoubleClick
Dim result As Boolean = False
If lstOrders.Text <> "" Then
result = True
Dim frm As New OrderForm
frm.MdiParent = Me.MdiParent
frm.Show()
frm.txtOrderNo.Text = DirectCast(lstOrders.SelectedItem, Order).ID.ToString
frm.btnFetch.PerformClick()
Else
MessageBox.Show("there are no orders here to click")
End If
End Sub
You'll need to go into the Order object and override the .ToString function so that the text in the Listbox displays whatever value you want (ie. Return ID & "," & " " & Server)

Related

Vb.net List within a list

So far I have the following code below. How to display each list value to textboxes?
Dim list As New List(Of String)
list.Add(dgvData.SelectedCells(0).Value.ToString)
list.Add(dgvData.SelectedCells(1).Value.ToString)
list.Add(dgvData.SelectedCells(2).Value.ToString)
list.Add(dgvData.SelectedCells(4).Value.ToString)
Dim val As String
For Each val In list
' MsgBox(val)
Next
Add your code in the CellEnter Event. You don't need to declare the list.
Private Sub YourDataGrid_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles YourDataGrid.CellEnter
txtbox1.Text = YourDataGrid.Item(col, row).Value.ToString
txtbox2.Text = YourDataGrid.Item(col, row).Value.ToString
txtbox3.Text = YourDataGrid.Item(col, row).Value.ToString
txtbox4.Text = YourDataGrid.Item(col, row).Value.ToString
end sub

Why is it only displaying one result

This program is supposed to accept in valid candidates for voting, add the names typed in a text box to a list box. In the list box the user may double click on the candidate they choose. After the tally button is clicked a list box displaying the candidates' Names and votes will appear along side the other list box.
My problem is that the lstTallies only displays the last voted candidate.
Below is my code
Public Class Form1
Dim maxVotes As Integer
Dim winner As String
Dim votes() As Integer
Dim index As Integer
Dim candidates As String
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
If Not isValidInput(txtNewCandidate.Text) Then
Exit Sub
End If
lstCandidates.Items.Add(txtNewCandidate.Text)
txtNewCandidate.Clear()
txtNewCandidate.Focus()
ReDim Preserve votes(index)
index += 1
End Sub
Private Function isValidInput(ByRef firstName As String) As Boolean
If IsNumeric(txtNewCandidate.Text) Or txtNewCandidate.Text = "" Then
MsgBox("Please input a valid candidate name.")
txtNewCandidate.Focus()
Return False
Else
Return True
End If
End Function
Private Sub btnTally_Click(sender As Object, e As EventArgs) Handles btnTally.Click
lstTallies.Visible = True
lblTally.Visible = True
lstTallies.Items.Add(lstCandidates.Text & " " & votes(lstCandidates.SelectedIndex))
End Sub
Private Sub lstCandidates_DoubleClick(sender As Object, e As EventArgs) Handles lstCandidates.DoubleClick
If lstCandidates.SelectedIndex = -1 Then
MsgBox("Select a candidate by double-clicking")
End If
votes(lstCandidates.SelectedIndex) += 1
MsgBox("Vote Tallied")
End Sub
End Class
Try this:
Assuming the index of the Candidate and his/her Vote are the same:
Private Sub btnTally_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnTally.Click
lstTallies.Visible = True
lblTally.Visible = True
For i = 0 To lstCandidates.Items.Count - 1
lstTallies.Items.Add(lstCandidates.Items(i).ToString & " - " & votes(i))
Next
End Sub
You cannot get the contents of the ListBox unless you iterate it.

create invoice from order XAF

I am trying to create an invoice from an order in XAF.
I follow the Add an Action that Displays a Pop-up Window from the devexpress web site
Using a View controller and an Action
I have an order class and order_Details class as a Collection of orders with an Invoice class and Invoice_Data class as a collection of Invoice
Private Sub Create_Invoice_Action_CustomizePopupWindowParams(sender As Object, e As CustomizePopupWindowParamsEventArgs) Handles Create_Invoice_Action.CustomizePopupWindowParams
Dim objectSpace As IObjectSpace = Application.CreateObjectSpace()
e.View = Application.CreateListView(Application.FindListViewId(GetType(elmts.OrderDetail)), _
New CollectionSource(objectSpace, GetType(elmts.OrderDetail)), True)
End Sub
Private Sub ShowNotesAction_Execute(ByVal sender As Object, _
ByVal e As PopupWindowShowActionExecuteEventArgs) Handles Create_Invoice_Action.Execute
Dim _invoiceDetails As elmts.InvoiceData = CType(View.CurrentObject, elmts.InvoiceData)
View.ObjectSpace.SetModified(_invoiceDetails)
For Each _nv_Det As elmts.OrderDetail In e.PopupWindow.View.SelectedObjects
If (Not String.IsNullOrEmpty(_invoiceDetails.ProductName)) Then
_invoiceDetails.ProductName += Environment.NewLine
End If
_invoiceDetails.ProductName += _nv_Det.Division
Next _nv_Det
Dim item As ViewItem = (CType(View, DetailView)).FindItem("ProductName")
CType(item, PropertyEditor).ReadValue()
'Save changes to the database if the current Detail View is displayed in the View mode
If TypeOf View Is DetailView AndAlso (CType(View, DetailView)).ViewEditMode = _
ViewEditMode.View Then
View.ObjectSpace.CommitChanges()
End If
End Sub
Private Sub PopupNotesController_Activated(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Activated
Create_Invoice_Action.Active.SetItemValue("ObjectType", DirectCast(View, DetailView).ObjectTypeInfo.Type Is GetType(elmts.Order))
End Sub​
Another words I like to from the Order detailView with an OrderDetailsCollection view add an action that will
Create the new Invoice and Commit the changes to the database
grab the Oder.OrderDetail Collection currentview items and pass them to the Newly created Invoice.InvoiceData Collection
Set the Order as Invoiced
Thanks for any help provided.
I hope this helps:
Private Sub Create_Invoice_Action_CustomizePopupWindowParams(sender As Object, e As CustomizePopupWindowParamsEventArgs) Handles Create_Invoice_Action.CustomizePopupWindowParams
Dim objectSpace As IObjectSpace = Application.CreateObjectSpace()
e.View = Application.CreateListView(Application.FindListViewId(GetType(elmts.OrderDetail)), _
New CollectionSource(objectSpace, GetType(elmts.OrderDetail)), True)
End Sub
Private Sub ShowNotesAction_Execute(ByVal sender As Object, _ByVal e As PopupWindowShowActionExecuteEventArgs) Handles Create_Invoice_Action.Execute
'Dim _invoiceDetails As elmts.InvoiceData = CType(View.CurrentObject, elmts.InvoiceData) << Wrong, since View.CurrentObject is elmts.Order
Dim _order As elmts.Order = CType(View.CurrentObject, elmts.Order);
Dim _invoiceDetails As elmts.InvoiceData = _order.CreateInvoice(); 'creates a new InvoiceData
View.ObjectSpace.SetModified(_invoiceDetails)
For Each _nv_Det As elmts.OrderDetail In e.PopupWindow.View.SelectedObjects
If (Not String.IsNullOrEmpty(_invoiceDetails.ProductName)) Then
_invoiceDetails.ProductName += Environment.NewLine
End If
_invoiceDetails.ProductName += _nv_Det.Division
Next _nv_Det
Dim item As ViewItem = (CType(View, DetailView)).FindItem("ProductName")
CType(item, PropertyEditor).ReadValue()
'Save changes to the database if the current Detail View is displayed in the View mode
If TypeOf View Is DetailView AndAlso (CType(View, DetailView)).ViewEditMode = _
ViewEditMode.View Then
View.ObjectSpace.CommitChanges()
End If
End Sub
Private Sub PopupNotesController_Activated(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Activated
Create_Invoice_Action.Active.SetItemValue("ObjectType", DirectCast(View, DetailView).ObjectTypeInfo.Type Is GetType(elmts.Order))
End Sub​

How to jump to a row of a DataView based on partial match search criteria?

Currently, my application uses the RowFilter property on an expression to search for a user-defined string within a DataView. Currently my code looks something like this:
Public Class MyClass
Private custView As DataView
Private Sub form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dsDataSet = <"DataAccessLayer call to SQL Stored Procedure">
custView = New DataView(dsDataSet.Tables(0))
custView.Sort = "Column Name"
Me.C1FlexGrid1.DataSource = custView
End Sub
Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
Dim searchText As String = txtSearch.Text
Dim expression As String = "Column Name LIKE '" + searchText + "%'"
custView.RowFilter = expression
Me.C1FlexGrid1.DataSource = custView
End Sub
End Class
My goal is to modify the behavior of this such that instead of filtering out rows that do not meet the search results, it will keep all rows present but jump to the first instance of a partial match as the user types in the search box. If DataView.Find() supported wildcards I would be set, but unfortunately it doesn't.
The solution I've come up with is to use some iteration logic. However this is done on the object the DataView has been bound to and not the DataView itself. Although this code can be modified to do exactly that.
Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
'Unselect all
Me.C1FlexGrid1.Select(-1, -1, True)
If txtSearch.Text <> "" And [column index] <> -1 Then
'Typed text
Dim s As String = txtSearch.Text.Trim.ToLower
Dim column As Int32 = [column index] + 1
'Recurse until match in first column is found
For i As Integer = 0 To Me.C1FlexGrid1.Rows.Count - 1
If C1FlexGrid1.GetData(i, column) <> Nothing Then
If C1FlexGrid1.GetData(i, column).ToString.ToLower.StartsWith(s) Then
Me.C1FlexGrid1.Select(i, column, True)
Exit Sub
End If
Else
MsgBox("Error message", vbOKOnly, "NO MATCHES")
'Reset search criteria
Call ResetSearch()
End If
Next
MsgBox("Error message", vbOKOnly, "NO MATCHES")
End If
End Sub

Public variable used for form opening not feeding through to from

Having some issues getting a form to populate based on a variable determined in current form.
I have a search result form that has a datagrid with all results, with an open form button for each row. When the user clicks this, the rowindex is used to pull out the ID of that record, which then feeds to the newly opened form and populates based on a SQL stored procedure run using the ID as a paramter.
However, at the moment the variable is not feeding through to the form, and am lost as to why that is. Stored procedure runs fine if i set the id within the code. Here is my form open code, with sci
Public Class SearchForm
Dim Open As New FormOpen
Dim data As New SQLConn
Public scid As Integer
Private Sub Search_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sql As New SQLConn
Call sql.SearchData()
dgvSearch.DataSource = sql.dt.Tables(0)
End Sub
Private Sub dgvSearch_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvSearch.CellContentClick
Dim rowindex As Integer
Dim oform As New SprinklerCardOpen
rowindex = e.RowIndex.ToString
scid = dgvSearch.Rows(rowindex).Cells(1).Value
TextBox1.Text = scid
If e.ColumnIndex = 0 Then
oform.Show()
End If
End Sub
End Class
The form opening then has the follwing:
Private Sub SprinklerCard_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Populate fields from SQL
Try
Call Populate.SprinklerCardPopulate(ID)
cboInsured.Text = Populate.dt.Tables(0).Rows(0).Item(1)
txtAddress.Text = Populate.dt.Tables(0).Rows(0).Item(2)
txtContactName.Text = Populate.dt.Tables(0).Rows(0).Item(3)
txtContactPhone.Text = Populate.dt.Tables(0).Rows(0).Item(4)
txtContactEmail.Text = Populate.dt.Tables(0).Rows(0).Item(5)
numPumps.Value = Populate.dt.Tables(0).Rows(0).Item(6)
numValves.Value = Populate.dt.Tables(0).Rows(0).Item(7)
cboLeadFollow.Text = Populate.dt.Tables(0).Rows(0).Item(8)
cboImpairment.Text = Populate.dt.Tables(0).Rows(0).Item(9)
txtComments.Text = Populate.dt.Tables(0).Rows(0).Item(10)
Catch ex As Exception
MsgBox(ex.ToString & "SCID = " & ID)
End Try
End Sub
Set the ID variable in the form before you open it.
If e.ColumnIndex = 0 Then
oform.ID = scid
oform.Show()
End If