cancel
Showing results for 
Search instead for 
Did you mean: 

Changing Grid columns type

Former Member
0 Kudos

Dear all,

I'm populating a grid using a DataTable and query (see code below).

I would like the FDatBill and NDatBill column are managed as Date type field, but they are managed as string.

How can set the column type of a Datagrid?

I had to cast every field of the query to populate the Grid using the DataTable.

' populate the grid
    Private Sub PopulateGrid()

        Try
            Dim ContractID As String = Get_Element_Value(CONTRACTID_ID)

            If ContractID = "" Then
                Exit Sub
            End If

            oForm.Freeze(True)

            
            ' prepare the query on the user table
            Dim sQuery As String = "SELECT T1.Code, T1." & UnitPric_UniqueID & _
                ", CONVERT(nvarchar, T1." & Type_UniqueID & ") As " & Type_UniqueID & _
                ", CONVERT(nvarchar, T1." & Included_UniqueID & ") As " & Included_UniqueID & _
                ", T1." & Currency_UniqueID & _
                ", CONVERT(nvarchar, T1." & UppBound_UniqueID & ") As " & UppBound_UniqueID & _
                ", CONVERT(nvarchar, T1." & Freq_UniqueID & ") As " & Freq_UniqueID & _
                ", CONVERT(nvarchar, T1." & FDatBill_UniqueID & ") As " & FDatBill_UniqueID & _
                ", CONVERT(nvarchar, T1." & NDatBill_UniqueID & ") As " & NDatBill_UniqueID & _
                ", CONVERT(nvarchar, T1." & QExcIn_UniqueID & ") As " & QExcIn_UniqueID & _
                ", T1." & EntryCod_UniqueID & _
                ", T1." & EntryDsc_UniqueID & _
                ", CONVERT(nvarchar, T1." & FreqRes_UniqueID & ") As " & FreqRes_UniqueID & _
                ", T1." & SubstOf_UniqueID & _
                " FROM " & SBO_CONTRACT_HEADER_TABLE & _
                    " T0 inner join [" & CONTRACT_ROWS_TABLE & "] T1 on T0.ContractId = T1.U_ContractID " & _
                " WHERE T0.ContractID = " & ContractID

            ' execute the query to populate the DataTable
            oForm.DataSources.DataTables.Item(CONTRACT_ROWS_DATATABLE).ExecuteQuery(sQuery)

            ' get the grid
            oGrid = oForm.Items.Item(GRID_CONTRACT_ROWS_ID).Specific

            ' Populate the Grid using the DataTable
            oGrid.DataTable = oForm.DataSources.DataTables.Item(CONTRACT_ROWS_DATATABLE)

            oColumns = oGrid.Columns

            ' set valid values
            SetGridComboValidValues()
            
        Catch ex As Exception
            MessageBox.Show("Errore: " & ex.Message)

        Finally
            oForm.Freeze(False)

        End Try

    End Sub ' end populating the grid

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

You are converting those fields to nvarchar in your query.

If you convert them to a date type (or do not convert them at all if they are already a date type) then it should work for you.

Former Member
0 Kudos

Thank you,

I thought I could manage only string values in grid columns.

Sorry... probably it's true only for comboboxes...

Regards

Emanuele

Edited by: Emanuele Croci on May 17, 2011 3:08 PM

Answers (0)