my program is not adding items to listbox and is freezing up - sql

im trying to add a very large amount of items to list box and what i need it for is i'm using to add selected items to itextsharp table report im using filters in the table just to display either the sales person who handled the customer or the date at which the incident occurred (or Issue was reported with the product) my filter system is as follows i have 4 categories which is 4 listboxes customer name, customer code(named listBox1 i have not got around to changing it yet) species name, and the error type my filter is placed under the searchBtn_Click event my filter and item adding code is as follows:
Private Sub searchBtn_Click(sender As Object, e As EventArgs) Handles searchBtn.Click
For Each obj As contactObject In custList
For Each item As speciesObject In speciesList
'loadLists()
If Trim(fromDate.Value) < Trim(obj.eventDate) Then
If Trim(toDate.Value) > Trim(obj.eventDate) Then
If Trim(fromDate.Value) < Trim(item.compDate) Then
If Trim(toDate.Value) > Trim(item.compDate) Then
End If
If Not customerListBox.Items.Contains(obj.customerName) Then
customerListBox.Items.Add(obj.customerName)
End If
If Not ListBox1.Items.Contains(obj.customer) Then
ListBox1.Items.Add(obj.customer)
End If
If Not speciesListBox.Items.Contains(item.name) Then
If ListBox1.Items.Contains(item.customerCode) Then
speciesListBox.Items.Add(Trim(item.name).ToUpper)
End If
End If
If Not errorListBox.Items.Contains(obj.issue + " - " + obj.issueDescription) Then
errorListBox.Items.Add(Trim(obj.issue + " - " + obj.issueDescription).ToUpper)
End If
End If
End If
End If
Next
Next
countErrors()
End Sub
then i have the query which is set up to get the customer info from the database system
Dim SqlText As String = "SELECT DISTINCT QEE.[EventID] ,QEE.[EventDate] ,QEE.[Employee] ,QEE.[Communication] ,QEE.[OtherCommunication] ,QEE.[Issue] ,QEE.[IssueDescription] ,QEE.[IssueComments] ,QEE.[Resolution] ,QEE.[ResolutionComments] ,QEE.[SalesOrderNumber] ,QEE.[CustomerPO] ,QEE.[SOStatus] ,QEE.[Customer] ,QEE.[CustomerName] ,QEE.[SalesPersonName] ,QEE.[IsResolved] ,QEE.[IssueValue] ,QEE.[DateAndTimeAdded] ,DATEDIFF(day, SOR.ReqShipDate, QEE.[EventDate]) AS Elapsed, SOR.ReqShipDate FROM [QualityTracking].[dbo].[tblQualityEventEntry] QEE INNER JOIN SysproCompanyC.dbo.SorMaster SOR ON QEE.SalesOrderNumber = SOR.SalesOrder COLLATE Latin1_General_CI_AS ORDER BY EventDate ASC, CustomerName ASC, SalesOrderNumber ASC;"
I could not fit all code on here
if you could also just general things to help as well i am new to vb.net but for other information things i have tried :
*listbox.startUpdate/endUpdate
*changing querys
*changing the sorted property (Right now its set for false)
*the issue happens when i choose select all and then hit search the database is holding almost 2Mil items and i need to be able to get it to move once i get it work stop freezing i will be able to increase the speed i just cant figure out totally where the issue is i know the query could be better probably (if you have any suggestions please feel free i'm learning)
*but i also see alot of people having this issue with listbox as being kinda a broken down way of listing items
*i have tried researching it and people have said use something else i cant do that for listbox is committed

Assuming Windows Forms.
You program might not be responding because of too many records to add, and each time you add an item into the ListBox.Items collection, the UI is refreshed.
You may either SuspendLayout while adding the lines into your Listbox, and ResumeLayout afterwards.
Private Sub searchBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
customerListBox.SuspendLayout();
// Place your code to populate the ListBox control here...
customerListBox.ResumeLayout();
End sub
This shall avoid a lot of refreshes from occuring while adding the items one by one and allow the application to lighten the add of items, then you resume the layout so that it refreshes the controls to display adequate information to the screen.
OR
You may use the ListBox.Items.AddRange() method along with List.ToArray().
Private Sub searchBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim custList As List(Of ConstactObject) = loadYourCustomers();
customerListBox.Items.AddRange(custList.ToArray());
Dim speciesList As List(Of SpeciesObject) = loadYourSpecies();
speciesListBox.Items.AddRange(speciesList.ToArray());
End sub
OR ELSE
I recommend using a DataGridView and setting its DataSource property to your list of objects.
So, in order to have the correct data, you'll have to:
Drop two DataGridView on your Form
Rename both DataGridView to a meaningful name (e.g. custListDataGridView, speciesListDataGridview)
Drop two BindingSource on your Form
Rename both BindingSource to a meaningful name (e.g. custListBindingSource, speciesListBindingSource)
In the designer, set the DataGridView.DataSource property to your respective BindingSource (e.g. custListDataGridview.DataSource = custListBindingsource, speciesListDataGridView.DataSource = speciesListBindingSource)
In the backing code, that is, in your searchBtn.Click event, you may set both your binding sources DataSource property
Private Sub searchBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim custList As IList(Of ContactObject) = loadYourContactObjects();
custListBindingSource.DataSource = custList;
Dim speciesList As IList(Of SpeciesObject) = loadYourSpeciesObject();
speciesListBindingSource.DataSource = speciesList;
End Sub
And your information data should be listed automatically without you having to manually add each record.

Related

vb.net insert data from listcheckbox to datagridview when an item checked and deleted when unchecked item

When I check a car make the car_model appear from database and when I check the car_model it's added automatically to datagridview1.
My question is when I try to check another car_make to add the new car_model of this car make to the DataGridView all the DataGridView items are deleted due to the (DataGridView1.Rows.Clear()) that I put in the code.
However, when I remove this comand the code duplicates every thing, can you help me solving this problem.
Private Sub acar_modelbox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles car_modelbox.SelectedIndexChanged
Dim itemChecked1 As Object
For Each itemChecked1 In car_makelistbox.CheckedItems
DataGridView1.Rows.Clear()
Next
Dim itemChecked2 As Object
For Each itemChecked2 In car_modelbox.CheckedItems
DataGridView1.Rows.Add(combobox1.SelectedItem("Id").ToString, (combobox1.SelectedItem("carvin").ToString, itemChecked1.item("car_make").ToString, itemChecked2.item("car_model").ToString)
Next
End Sub

How can I filter a ListView using TextBox and ComboBox?

Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
ListView2.Items.Clear()
Dim curSelectionCombobox As String = ComboBox2.SelectedItem.ToString()
ListView2.Items.Add(listitm)
End Sub
Well basically this is what ive come up with the filtering thing in combobox which is obviously wont work
and in the combobox and button i didnt get to try coding those but im quite sure it wont work either im new in this language and im struggling to catch up giving the fact that this pandemic really gets me more and more stupider as the day passed by
Well my main problem is that the filtering in the groupBox_bookShelf is when i choose a genre in the combobox the static listview will filter leaving only the exact items its genre selected in the combobox
the second is the combobox and button im aiming to link the action of both property when filing in the groupBox_bookInformation then once the filter button is clicked i want to filter the lower listview leaving only the selected genre and its items
Here is the sample form ive been working on.
enter image description here
I am guessing that what is selected in the combo box is a value that appears in some of your list view items.
Start by calling .BeginUpdate() This will prevent the user interface from repainting on each update which would really slow things down.
I loop through the items and test one of the sub items to see if it matches the combo selection. If it does not match is is removed.
Be sure to call .EndUpdate or the changes will not show up.
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
Dim curSelectionCombobox As String = ComboBox2.SelectedItem.ToString()
ListView2.BeginUpdate()
For Each lvi As ListViewItem In ListView2.Items
If lvi.SubItems(6).Text <> curSelectionCombobox Then
lvi.Remove()
End If
Next
ListView2.EndUpdate()
End Sub

How to get certain column value from selected row to apply to filter?

I'm a complete beginner in VB.NET
I have a task to make a form on visual studio and part of it is to make a functional button for report on orders. On navgrid portion of the form I have master object orders list with order id and order date while in datagridview a child object orderslist with details about the order
I need a button that would give me a report on selected order.
I have made a report already and the code for button so far looks like this:
Private Sub BarButtonItem1_ItemClick_1(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick
CR3.OpenReport("arpt_Sales_Orders", "FilterHere")
End Sub
if the FilterHere part is left empty, i get report on ALL the orders with their details.
I have been trying to look for how to filter out what i need but with little success.
I have also tried to look into how to get value from order list (navgrid on the right) but I'm starting to think this is not gonna bring any use. Nevertheless here are my attempts at this so far
Dim vOrderID = atbv_Sales_Orders.CurrentRow(colOrderID)
Dim data As Object = NavGridView.SelectedRow(colOrderID);
Help would be appreciated. I've been on this for hours with little success
EDIT:
To my understanding i need to add to filter section
OrderID = (OrderID value from selected order)
So the question probably stands as, how do i get that value?
Ok, I have finally found the answer myself. Posting it if someone would come across similiar issue.
First row sets event to fire on pressing the button. Next two are what i needed
Private Sub BarButtonItem1_ItemClick_1(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick
Dim vOrderID As Integer = CInt(cOrderID.Text)
CR3.OpenReport("arpt_Sales_Orders", "OrderID = '" & vOrderID & "'")
End Sub
Works flawlessly for me

Add Textbox values in CheckedListBox( as items) using VB.net

i'm using vb.net to make a UI that connects via RS232. the 1st output that i defined is some kinda list of products, that i defined to be showed in a textbox.
Now i need to add items to that checkedlistbox. Don't mind the full list , think as it was only 1 product .
Example, textbox1.text="apple", so i want add the item "apple" to the listbox.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
SerialPort1.Write("Products" & vbCr)
Dim separated = TextBox1.Text.Split(";")
CheckedListBox1.Items = separated.Text 'i know this is wrong :('
End Sub
i tried everything , but there's no similar question anywhere. and pls, tell me what i've done wrong in the post before downvote ! cumps
Items is readonly. You need to use Add or AddRange. Since you're creating an array already, change it to this.
Dim separated = TextBox1.Text.Split(";")
CheckedListBox1.Items.Clear()
CheckedListBox1.Items.AddRange(separated)

Connect Treeview Child Node to Database Details

I'm working with VB.net 2010 & have a Treeview that's being populated from a MySQL table via a Dataset in the Form1_Load.
The treeview loads the test data from the database table fine but I want to be able to click a treeview Child Node & display the matching data from the MySQL table Row inside multiple textbox.
I know I need to have a textbox for each table Cell in a Row but I can't figure out how to connect the table Row ID column to the treeview (child node). My table ID column is named UserID in the screenshot below.
I also know I need to add code to the TreeView1_AfterSelect. I think I might be able to use the treeview node Tag to connect to the table UserID column, but I'm just not sure about the code.
My treeview root node is set in design view.
I only have a Binding Navigator & Datagrid on the Form while testing the treeview/table-details, those will eventually be removed from the Form.
Here's some background on how I'm loading the treeview with my test data from the MySQL table.
Here's some screenshots of my Table data & the VB.NET Form, this site won't let me post images.
MySQL Table Data
VB.NET Form image
I've been trying to get this to work for at least a week with no luck. Any help would be very much appreciated.
Private Sub AddNode(parentNode As String, nodeText As String)
Dim node As New List(Of TreeNode)
node.AddRange(TreeView1.Nodes.Find(parentNode, True))
If Not node.Any Then
'' '' ''This is the Parent Treeview Node
node.Add(TreeView1.Nodes(0).Nodes.Add(parentNode, parentNode))
End If
'' '' ''This is the Child Treeview Node
node.Add(TreeView1.Nodes(0).Nodes(parentNode).Nodes.Add(nodeText, nodeText))
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Database1DataSet.Table44' table. You can move, or remove it, as needed.
Me.Table44TableAdapter.Fill(Me.Database1DataSet.Table44)
For Each dr As DataRow In Database1DataSet.Table44.Rows
AddNode(dr("ParentNode").ToString, dr("ChildNode").ToString)
Next
TreeView1.ExpandAll()
End Sub
Your database structure doesn't quite make sense to me. Can there be more than one city per state? Or is it always one user and one city. It's not clear.
Anyway, you can use the node's Key parameter to set the Name property, and see what you clicked on:
Private Sub AddNode(parentNode As String, nodeText As String, userID As String)
Dim node As New List(Of TreeNode)
node.AddRange(TreeView1.Nodes.Find(parentNode, True))
If Not node.Any Then
node.Add(TreeView1.Nodes(0).Nodes.Add(parentNode, parentNode))
End If
node.Add(TreeView1.Nodes(0).Nodes(parentNode).Nodes.Add(userID, nodeText))
End Sub
Then in your AfterSelect event, see if your key is a number:
Private Sub TreeView1_AfterSelect(sender As Object, e As TreeViewEventArgs) _
Handles TreeView1.AfterSelect
Dim userID As Integer = 0
If Integer.TryParse(e.Node.Name, userID) Then
' do something with userID
End If
End Sub