Active filtering datagridview with texbox when datagridview has a checkbox column - vb.net

Ι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)

Related

How to Fill ComboBox with DataTable Column Names in VB.NET?

I need to fill a combobox on a form with the column names from an existing data table. I don't want to manually enter the column names in case they change in the future. I also want to keep my code tidy, so I don't want a standard loop. How can I fill a combobox with the column names most efficiently?
Thanks to examples from here, here, and here, I was able to piece together the following LINQ query and set it directly to the data source on the combobox when the form loads.
Private Sub Form_Load(sender As Object, e As EventArgs) Handles Me.Load
comboBox.DataSource = (From dc In dataTable.Columns
Select dc.ColumnName).ToArray()
End Sub

VB.Net - Display Yes/No in a Combobox but have a value of 1/0

This one is really kicking my butt, i'm hoping someone can point me in the right direction.
I have a combobox on my form that i need to display a "yes" and a "no" instead of a "0" and "1" BUT to process a "0" and "1" depending on the selection. Make sense?
I have the 0 and 1 sitting in the Data > Items > Collection properties of the combobox.
I have tried playing around with the DisplayMember property and the ValueMember property but i cant seem to get these working.
Any ideas would be much appreciated!
In your Data > Items > Collection properties of the combobox
Delete every line in there and add the following, (in the same order)
NO
YES
Now double click on your combobox in the form in design mode.
In the event subroutine for the combobox - selected index changed event, add the following:
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
UserChoseReloadSurvey = ComboBox1.SelectedIndex
End Sub
And that will save either a 1 or 0 in a variable named UserChoseReloadSurvey.
Taking it for granted that you have an integer variable named UserChoseReloadSurvey

Performing an action when a combobox value is selected

I'm having some trouble doing something that seems very simple but I just don't know what I'm doing wrong....
On Form_Load I populate a combobox with
Datasource
DisplayMember
ValueMember
Here I set .selectedindex = - 1 so that nothing is selected. The combobox gets populated properly and everything is bells and whistles.
Now when user selects something from the drop down, I want to populate a DataGrid with a bunch of info based off the VALUE selected. So I pass and ID into the function that populates the DataGrid.
I'm trying to do this like this...
Private Sub cbo1_SelectedValueChanged(sender As Object, e As EventArgs) Handles cbo1.SelectedValueChanged
dim productID as string=""
cbo1.SelectedValue = ProductID
Call PopulateProductGrid(ProductID)
End Sub
I also have tryined with SelectedIndexChanged, but for both event I get an error
Cannot set the SelectedValue in a ListControl with an empty
ValueMember.
I'll wager that the issue is that you're binding in the wrong order. You should always set the DataSource last, not first. Try changing that and see if your issue goes away. The problem is that setting the DataSource means that the control is bound, so an item will be selected and the appropriate events raised before you have set the DisplayMember and ValueMember.

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

winforms vb 2008 textbox validation issue

I have vb 2008 Winforms application.
In my Branch form I have 11 textbox fields and I want to validate 8 of them, either mandatory, or required format such as UK postcode, UK tel nos etc.
My issue now is that when the validation starts, it is validating the last text field first ( or seems to be)
here is my code
For Each oCtrl As Control In Me.Controls
If TypeOf oCtrl Is TextBox Then
oCtrl.Focus()
If Validate() = False Then
Exit Sub
End If
End If
Next
what's wrong please?
what's wrong please?
The controls collection isn't sorted or grouped. Your loop will access them in whatever order the collection has them.
Without more code it's hard to say how to fix it. However a tip may be in order. Use the same handler to handle the validate event for each textbox. This way you can keep the user at that textbox until the input is valid.
is it possible to add the items to the collection in the order of their tab indexes on form Shown event, how would I do that please?
A List(Of TextBox) and a custom sorter would probably be the way to go
Dim AllTB As New List(Of TextBox)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
AllTB.AddRange(Me.Controls.OfType(Of TextBox))
AllTB.Sort(Function(x, y) x.TabIndex.CompareTo(y.TabIndex))
End Sub
To loop through the textboxes use:
For Each tb As TextBox in AllTB
Because the TextBoxes are in the list by reference you can get or set any of the properties in the textboxes and any changes, will be reflected on your form. You could also use sequential names for the textboxes, tag property, etc. and sort by that.