Using Combo Box text for part of a Binding Source - vb.net

Hello I am trying to display data in a grid view using a combo box containing multiple databases. Each database has a binding source. However, instead of coding a huge select statement is there a way that I can use the TableList.SelectedText and put it in front of the BindingSource so I don't have to code so many instances?
I tried doing it below but it does not work.
Private Sub TableList_SelectedIndexChanged(sender As Object, e As EventArgs) Handles TableList.SelectedIndexChanged
DataGridView1.DataSource = TableList.SelectedText(BindingSource)
DataGridView1.AutoGenerateColumns = True

Related

Create a IBindingGridView list for binding source using VB.net

I am creating a windows form application. I am using AdvanceDataGridView for filtering and sorting purpose. I have written this code:
Private Sub AdvancedDataGridView1_FilterStringChanged(sender As Object, e As EventArgs) Handles AdvancedDataGridView1.FilterStringChanged
Me.BindingSource1.Filter = Me.AdvancedDataGridView1.FilterString
End Sub
And in the load
Using db As New Entities
BindingSource1.DataSource = db.tableName.ToList
AdvancedDataGridView1.DataSource = BindingSource1
End Using
But still I am not getting filtered records in grid.
After searching I found that to enable filtering we need to use IbindingSourceList. But how to create that type of data? Or is there any other way to make this filtering work.
I am using VB.net.

VB 2013: how to update database using datagridview values

I have a DGV in my form that can be edited. I want to write back the updated values to the database so that they are available for next read.
I searched for answers around net and found couple of ways of doing it by opening a connection and updating it. However, i was wondering if there is any direct way of updating the database by using a single command.
I am a novice at VB and learning it only for a library project, hence find it difficult to understand and implement statements that deal with SQLs in the code. pls help... thanks
The proper approach to this is to use a data adapter to populate a DataTable that you then bind to the grid, then use the same data adapter to save the changes from that table back to the database. E.g.
Private adapter As New SqlDataAdapter("SELECT * FROM MyTable", "connection string here")
Private builder As New SqlCommandBuilder(adapter)
Private table As New DataTable
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Query the database and populate the DataTable.
adapter.Fill(table)
'Bind the data to the UI.
BindingSource1.DataSource = table
DataGridView1.DataSource = BindingSource1
End Sub
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
BindingSource1.EndEdit()
'Save the changes back to the database.
adapter.Update(table)
End Sub
The BindingSource would be added to the form in the designer.

Auto Complete Text Box from Access database

I have a text box "Textbox1" and a set of 30,000 words stored in an access database. I would like to set the VB Textbox1's auto complete source to the access database. How do I do this in vb.net? I am a novice programmer at present.
Sample:
From an access Database
Create a DataSet in your vb project, connected to that database
Add New Item -> Data -> DataSet
In your .xsd designer, add a new TableAdapter, connect it to your Access file, create a query.
Query and add them to the TextBox.AutoCompleteCustomSource
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'NamesDataSet.Names' table. You can move, or remove it, as needed.
Me.NamesTableAdapter.Fill(Me.NamesDataSet.Names)
'get my names from the dataset
Dim myNames = From n In NamesDataSet.Names Select n.Name
TextBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend
TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
'add names to custom list
TextBox1.AutoCompleteCustomSource.AddRange(myNames.ToArray())
End Sub

Simple, but I'm stuck ....Updating a DataSet using code

I have a simple Windows form in VB: textbox bound thru an adapter and a bindingsource to my dataset.
I have a button that on Click I want it to update the database. The form loads and the first data row shows in the textbox, I change the text then click my button but no update happens.
Any ideas what I'm doing wrong, or how I should do this??
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.AToolsTableAdapter.Fill(Me.Qedsandb_TroyDataSet.aTools)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
AToolsTableAdapter.Update(Qedsandb_TroyDataSet.aTools)
End Sub
End Class
Assuming the click event runs(?), TableAdapters based on a query (a join) do not, by default, have the ability to update the database. The name of your binding source suggests that you are using a query.
MSDN: TableAdapter Overview
The update functionality of a TableAdapter is dependent on how much
information is available based on the main query provided in the
TableAdapter Wizard. For example, TableAdapters that are configured to
fetch values from multiple tables (JOINs), scalar values, views, or
the results of aggregate functions are not initially created with the
ability to send updates back to the underlying database. However, you
can configure the INSERT, UPDATE and DELETE commands manually in the
Properties window.
You don't appear to be moving the data back from the form to the dataset. Try calling EndEdit on your bindingsource.

How can you make new form as a copy (in runtime) of an already shown form?

I am trying to make a form that functions as "READ/OPEN MAIL".. so what I want is to have multiple forms (which is a copy, with both the designer and form functions e.g. buttons and codes) when I open multiple mails.
I know how to create a new window but I do not know how to copy the designer codes and functions from anoher form and apply it to the newly created form. I have searched google but it only directs me to different questions. Thanks in advance!
All you have to do is create a variable of the type of your class, then show it using the Show method.
i.e.
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim myform As Form1 = New Form1
myform.Show()
End Sub