how to clear a listview from another form in vb.net - vb.net

I would like to know, how to clear a list view items from an another form. For instance, I have Form A with a ListView, I would like to clear the Form A ListView Items from Form B. What I tried is, create a function in Form A to clear the listView and call that function from Form B. But it is not working. Please help me to resolve this issue.

Here is a quick and easy way to do so; this removes all items from listbox using a for each...
Private Sub btnClearListView_Click(sender As System.Object, e As System.EventArgs) Handles btnClearListView.Click
For Each I In FormA.ListView1.Items
FormA.ListView1.Items.Remove(I)
Next
End Sub
Thanks!

Related

How to connect Radiobutton to a textbox?

I'd like to create sample applications, like examination system. I don't know how to connect radio button and textbox to create multiple choices in this system. So can anyone can tell me how to connect radiobutton and textbox to create multiple choices?
If i understand your question correctly:
Radio buttons have 'text' property, you can put your description there.
Next, this code should place this Text description in TextBox after clicking this particular RadioButton:
Private Sub RadioButton_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton.CheckedChanged
TextBox.ext = RadioButton.text
End Sub
If not, you can always look for answer here:
https://www.tutorialspoint.com/vb.net/vb.net_radio_button.htm

Dynamically added DataGridView

I have a datagridview that i use to filter another datagridview containing data.The filterGrid is added dynamically.
The screen shot shows that i have a MODAL form in order to look up for a record in the database.When I click where the arrow is ,this modal form appears with 2 datagridview.Everyhting is working fine.BUT when i want to look up fagain or a record from another window the filter datagridview is added with columns of the previous form.I think there's something that i must dispose.
In the event leave of the form i'm disposing the header grid to clean it in order to have a new filter grid added in the nex search that i will do accoriding to the datagridview that contains data but it doesn't work
Private Sub Frm_listeRecherche_Leave(sender As Object, e As System.EventArgs) Handles Me.Leave
Me.Controls.Remove(HeaderGrid)
HeaderGrid.Dispose()
End Sub
Public Sub New()
InitializeComponent()
End Sub

Select and Show new Tab on control when values in txtbox change, but keep focus on txtbox

I'm having this issue that should be pretty easy to solve but I just can't seem to figure it out or find an answer yet. I have the following code:
Public Sub NotifyThatValuesChanged(sender As Object, e As EventArgs)
APIUserForm_MAIN.OnSecurityInputValuesChanged()
APIUserForm_MAIN.MessageSender.TabControl.SelectTab(0)
End Sub
So, I'm rasing events when values within txtboxes change, and one of the things I want to do is change tab focus when these values change, which it is doing...but....I don't want the cursor (or focus) to change to the selected tab. I want the cursor/focus to stay where it is at while this event happens, and for the tab selected on this other control to change from (1) to (0).
Thanks for the help!!!!
I don't think it's 100% possible. Try putting the focus back into the textbox:
Public Sub NotifyThatValuesChanged(sender As Object, e As EventArgs)
APIUserForm_MAIN.OnSecurityInputValuesChanged()
APIUserForm_MAIN.MessageSender.TabControl.SelectTab(0)
TextBox1.Select()
End Sub
If multiple controls are calling this method, you can use the sender parameter:
DirectCast(sender, Control).Select()

how to add combobox items in listbox or listview

I want to know what control to be use on my project is it Listview or listbox???. I have a comboBox control on my project what I want to do is when I selected 1 item on my combobox it will automatically add on listbox or listview and when I selected more than 1 item I want to add it on listbox or listview on newline...
Is it simple, please help me to do that in listbox or listview..thanks!
Listbox > Is for viewing too but user can select it
Listview > Is for viewing only, user cannot select also it viewing by five view directly cause it's for viewing only
If your project wanted the list to be viewing from what have been select by Combobox, then you just pick List View, but if you want for viewing also user can select it, better use listbox, so it's up to you.
Also you can know how the Tools work by focus your mouse cursor to the tool, then it will pop up an tooltip that write what the tool for.
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
ListView1.Items.Add(ComboBox1.SelectedIndex)
End Sub
That is the code to viewing in listview for what you select in combobox
For clearing all the item in the Listview or listbox, just write to your form_load
Listview.items.clear
Why i said in form load, cause the list just for viewing, of course every time the form begin to run, it will need blank list, so the best is put in form load
UPDATE
To remove the selected index in listbox
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
ListBox1.Items.Remove(ListBox1.SelectedItem)
End Sub
ListView Items can be selected a couple of ways In the Properties window for the ListBox the activation property allows an item to be activated by one click or two clicks. Here is an example of how the selected items can be used
If Me.ListView1.SelectedItems.Count = (1) Then
'Declare the selected item
Dim lviSelectedItem As ListViewItem = Me.listView1.SelectedItems(0)
'Now you can use it
lblLabel1.Text = lviSelecetedItem.Text
Else
lblLabel2.Text = "You can make Items selectable by switching CheckBoxes property to True in the Properties windows and using CheckBox event handlers"
End If

Datagridview not saving changes to DB when Navigator save changes clicked

This is a VB.NET, Winforms App, Using EF. On my form I have a datagridview, a databinding source, and a bindingNavigator... I can edit the cells of the datagridview but when I click save changes the value is only saved until I reload the form.?.? Looking at the database table directly I can see the value never actually changes.. Below is the sub that handles the click..
Private Sub UnitBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UnitBindingNavigatorSaveItem.Click
UnitDataGridView.CommitEdit(DataGridViewDataErrorContexts.CurrentCellChange)
db.SaveChanges()
End Sub
From what I have read this seems like all I need to have but obviously its wrong somehow..
I made a work around for it for the time being... I simply use the CellEndEdit event and get the row info from that. Next I get the value of the column that holds the id and update the database from there. Seems like a long way around but is the only way I can get it to write any data at the moment...