on 05-17-2011 1:28 PM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
11 | |
6 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.