Dynamically added DataGridView - vb.net

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

Related

Active filtering datagridview with texbox when datagridview has a checkbox column

Ιn VB.NET i have a datagridview which has as datasource a datatable.
In order to achieve active filtering, i have a textbox with the follwing code on TextChanged event.
Private Sub KryptonTextBox1_TextChanged(sender As Object, e As EventArgs) Handles KryptonTextBox1.TextChanged, KryptonTextBox5.TextChanged
DirectCast(KryptonDataGridView1.DataSource, DataTable).DefaultView.RowFilter = String.Format("userid like '%{0}%' or name like '%{0}%'", KryptonTextBox1.Text)
End Sub
When i decided to use a checkbox type column , i saw that when a user has made some checks and then he filters, the checks are lost beacuse the datatable is reloaded ...
Any ideas ? (except storing the checked values in the database because i have no rights to do this in the specific case)

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

how to clear a listview from another form in 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!

Showing List of combobox while getting focus (vb.net)

When we click on drop down combobox control in our windows form, it shows the list automatically.
But when we press tab and navigate to that control from keyboard it doesn't shows the list automatically. So in other to show the list automatically on receiving focus what should be done?
Set the DroppedDown property of the combobox equal to true.
Private Sub myComboBox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles myComboBox.GotFocus
myComboBox.DroppedDown= true
End Sub
I would like to mention on thing here.
I used Enter event to show Drop down list with DroppedDown=true,
But When I type something in text area of combobox and if i leave the area to next control, entered text is lost.
My combobox is databound.