Hi all,
I desperately need help here.
Currently, I have a dynamic datagrid which actually is used for search function. So the columns and the the format is actually dynamic depending on which search the user clicked on...
However, I am trying to format certain columns in my grid to date and currency format. But after trying for several hours and surfing thru the websites, i am still unable to format the columns..
The vb.net application is actually linked to mssql2000. the date are stored as decimal in mssql as yyyymmdd.
Please do help me out... I really have a deadline to meet and until now, i am still stuck here. Thanks alot in advance.
The following are my codes.
=======================================================
Private Sub LoadGrid()
Dim mGridTableStyle As New DataGridTableStyle
Dim col_counter As Integer
Dim CleanMapName As String
With mGridTableStyle
.MappingName = TableField
.PreferredRowHeight = 18
.ReadOnly = True
With .GridColumnStyles
For col_counter = 0 To SelectFields.Length - 1
.Add(New DataGridTextBoxColumn)
With .Item(col_counter)
CleanMapName = Replace(SelectFields(col_counter), "[", "", , , CompareMethod.Binary)
CleanMapName = Replace(CleanMapName, "]", "", , , CompareMethod.Binary)
.MappingName = CleanMapName
.HeaderText = SelectCaptionFields(col_counter)
If Alignment(col_counter) = "Left" Then
.Alignment = HorizontalAlignment.Left
ElseIf Alignment(col_counter) = "Center" Then
.Alignment = HorizontalAlignment.Center
ElseIf Alignment(col_counter) = "Right" Then
.Alignment = HorizontalAlignment.Right
End If
.Width = SelectWidth(col_counter)
.NullText = String.Empty
.ReadOnly = True
If FormatFields(col_counter) = "Currency" Then
Dim tbc As DataGridTextBoxColumn
tbc = CType(mGridTableStyle.GridColumnStyles(CleanMapName), DataGridTextBoxColumn)
Dim CulInfo As New CultureInfo("en-US", False)
tbc.FormatInfo = CulInfo
tbc.Format = "c"
ElseIf FormatFields(col_counter) = "Date" Then
Dim tbc As DataGridTextBoxColumn
tbc = CType(mGridTableStyle.GridColumnStyles(CleanMapName), DataGridTextBoxColumn)
Dim CulInfo As New CultureInfo("en-US", False)
tbc.FormatInfo = CulInfo
tbc.Format = "d"
End If
End With
Next col_counter
End With
End With
DGSearch.TableStyles.Clear()
DGSearch.TableStyles.Add(mGridTableStyle)
DGSearch.Refresh()
End Sub
I desperately need help here.
Currently, I have a dynamic datagrid which actually is used for search function. So the columns and the the format is actually dynamic depending on which search the user clicked on...
However, I am trying to format certain columns in my grid to date and currency format. But after trying for several hours and surfing thru the websites, i am still unable to format the columns..
The vb.net application is actually linked to mssql2000. the date are stored as decimal in mssql as yyyymmdd.
Please do help me out... I really have a deadline to meet and until now, i am still stuck here. Thanks alot in advance.
The following are my codes.
=======================================================
Private Sub LoadGrid()
Dim mGridTableStyle As New DataGridTableStyle
Dim col_counter As Integer
Dim CleanMapName As String
With mGridTableStyle
.MappingName = TableField
.PreferredRowHeight = 18
.ReadOnly = True
With .GridColumnStyles
For col_counter = 0 To SelectFields.Length - 1
.Add(New DataGridTextBoxColumn)
With .Item(col_counter)
CleanMapName = Replace(SelectFields(col_counter), "[", "", , , CompareMethod.Binary)
CleanMapName = Replace(CleanMapName, "]", "", , , CompareMethod.Binary)
.MappingName = CleanMapName
.HeaderText = SelectCaptionFields(col_counter)
If Alignment(col_counter) = "Left" Then
.Alignment = HorizontalAlignment.Left
ElseIf Alignment(col_counter) = "Center" Then
.Alignment = HorizontalAlignment.Center
ElseIf Alignment(col_counter) = "Right" Then
.Alignment = HorizontalAlignment.Right
End If
.Width = SelectWidth(col_counter)
.NullText = String.Empty
.ReadOnly = True
If FormatFields(col_counter) = "Currency" Then
Dim tbc As DataGridTextBoxColumn
tbc = CType(mGridTableStyle.GridColumnStyles(CleanMapName), DataGridTextBoxColumn)
Dim CulInfo As New CultureInfo("en-US", False)
tbc.FormatInfo = CulInfo
tbc.Format = "c"
ElseIf FormatFields(col_counter) = "Date" Then
Dim tbc As DataGridTextBoxColumn
tbc = CType(mGridTableStyle.GridColumnStyles(CleanMapName), DataGridTextBoxColumn)
Dim CulInfo As New CultureInfo("en-US", False)
tbc.FormatInfo = CulInfo
tbc.Format = "d"
End If
End With
Next col_counter
End With
End With
DGSearch.TableStyles.Clear()
DGSearch.TableStyles.Add(mGridTableStyle)
DGSearch.Refresh()
End Sub