سؤال

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")
هل كانت مفيدة؟

المحلول

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

نصائح أخرى

Your other option is to not use AutoGenerateColumns="True" in the GridView markup, but rather use BoundColumn or TemplateColumn declarations to control what data is visible to the end user, while still having the data available for use (i.e. ID value).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top