Search code examples
mysqlvb.netdatagridviewdatasetdatagridcolumn

Filter what to show in DataGridView vb.net


I'm trying to get user's projects with ID and title from database, but I only need to show the title of project. In same time, I need the id to be retrievd from database as I need it (2nd question) so that when I click in a button, it will open a new form with all details of selected item from datagrid (As I can't use sql query with where title=title but I have to use ID)

Here is my so simple code which is working but showing ID and title :

    Dim DataAdapter As New MySqlDataAdapter("SELECT id, title From project;", MySqlConnection)
    Dim ds As New DataSet
    DataAdapter.Fill(ds, "Projects")
    DataGridView1.DataSource = ds.Tables("Projects")

Solution

  • To show only "Title" you may do this ..

    DataGridView1.Columns("id").Visible = False
    

    As your sample .. assumed you show Form2

    Form2.TextBox1.Text = DGCurrentJob.CurrentRow.Cells(0).Value
    
    Form2.TextBox2.Text = DGCurrentJob.CurrentRow.Cells(1).Value
    
    Form2.ShowDialog()