VB 2005 Express - datagridview

Hai,

I would like to make a datagridview, see example

i want 4 dings

1. combobox of column keuze
2. show valuta right
3. datetimepicker
4. edits directly to database

De code below wont do the job.

        Dim aDataTable As DataTable = New DataTable
        Dim aSQL As String = "SELECT Tabel1.Id, Tabel2.Tekst, Tabel1.String, Tabel1.Valuta, Tabel1.Integer, Tabel1.Datum " & _
                            "FROM Tabel2 INNER JOIN Tabel1 ON Tabel2.Id = Tabel1.Keuze"
        Dim aConnection As OleDbConnection = getConnectionString()
        Dim aDataAdaptor As OleDbDataAdapter
        Dim aCommand As OleDbCommand
        Dim aCommandBuilder As OleDbCommandBuilder

        Try
            aConnection.Open()
            aCommand = New OleDbCommand(aSQL, aConnection)
            aDataAdaptor = New OleDbDataAdapter(aCommand)
            aCommandBuilder = New OleDbCommandBuilder(aDataAdaptor)
            aDataAdaptor.Fill(aDataTable)
        Catch ex As InvalidOperationException
            MessageBox.Show(ex.Message)
        Catch ex As OleDbException
            MessageBox.Show(ex.Message)
        Finally
            aConnection.Close()
        End Try



Answer this question

VB 2005 Express - datagridview

  • Warren Lee

    hi,

    datagridview is just to display or to format the output from the datasource, so i don't think it will recognize anytype but you can do so through datagridview columns because each column

    hope this helps



  • Ramon Casha

    thank you very much

    1. do you have an exemple code

    2. Is it possible to set the timer picker based on the datatype (date) instead of the name

     _subcatDataGridView.Columns(e.ColumnIndex).Name = "datum"


  • Jim Loo

    hi,

    make a dataset and load both of your table indvidualy , at the top of this forum there is a FAQ thread you will find a question about how to make a combobox to  "LookUp " for values from other table

    for the time picker  you can use something like this

    Private Sub MyDataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)

            If _subcatDataGridView.Columns(e.ColumnIndex).Name = "datum" AndAlso e.RowIndex > -1 Then

                      //ToDo : open the dattimepicker

                     MyDataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value= "picked date"

            End if

    End Sub

     

    after you finish editing and click save button or form close event handler you can write SQL update statment

    hope this helps



  • VB 2005 Express - datagridview