G
Guest
Hi,
Im Sure this is a standard question and one of those its easy if you know how.
Basically I am returning a dataset from sql server with five fields but only
want to display to columns in my datagrid populated from two fields from the
dataset
So ive
a) created a grid datagridstyle
b) Ive created a datatable to map the data from my dataset
c) Ive retrieved the data from sql server and copied the appropriate fields
to the grids datatable
It appears that all the styles are being ingnored and all the data from the
sql data set are being displayed
Any Ideas ?
Code included TIA
Private objEventParamDT As New DataTable("eventParamDT")
Private Sub populate_eventParams(ByVal p_nIdEvent As Integer)
Dim objDataSet As DataSet
Dim objEventParamRow, objDataRow As DataRow
Try
objDataSet = objEvent.getEventArgList(p_nIdEvent)
Call create_eventParamDataTable()
Call create_EventParamsGrid()
For Each objDataRow In objDataSet.Tables("results").Rows
objEventParamRow = objEventParamDT.NewRow
objEventParamRow("argSeq") = objDataRow("argSeq")
objEventParamRow("argDesc") = objDataRow("argDesc")
objEventParamDT.Rows.Add(objEventParamRow)
Next
With dgEventParams
.DataMember = "eventParamDT"
.DataSource = objEventParamDT
End With
MsgBox(dgEventParams.TableStyles.Item(0).GridColumnStyles.Item(0).HeaderText)
Catch ex As Exception
setStatus(ex.Message)
End Try
End Sub
Private Sub create_eventParamDataTable()
Dim nLeventId As New DataColumn("idLeventArg", GetType(Integer))
Dim nSeq As New DataColumn("argSeq", GetType(Integer))
Dim cArgDesc As New DataColumn("argDesc", GetType(String))
With objEventParamDT
' .Columns.Add(nLeventId)
.Columns.Add(nSeq)
.Columns.Add(cArgDesc)
End With
End Sub
Private Sub create_EventParamsGrid()
Dim gts As New DataGridTableStyle
dgEventParams.TableStyles.Clear()
gts.MappingName = "EventParamData"
' Set other properties.
gts.AlternatingBackColor = Color.LightGray
' Add a GridColumnStyle and set its MappingName
' to the name of a DataColumn in the DataTable.
' Set the HeaderText and Width properties.
' Dim txtEventId As New DataGridTextBoxColumn
' With txtEventId
' .MappingName = "idLeventArg"
' .HeaderText = ""
' .Width = 0
' .ReadOnly = True
' End With
'
Dim txtSeq As New DataGridTextBoxColumn
With txtSeq
.HeaderText = "Seq"
.MappingName = "argSeq"
.Width = 10
.ReadOnly = True
End With
gts.GridColumnStyles.Add(txtSeq)
Dim txtDesc As New DataGridTextBoxColumn
With txtDesc
.HeaderText = "Description"
.MappingName = "argDesc"
.Width = 200
.ReadOnly = True
End With
gts.GridColumnStyles.Add(txtDesc)
With dgEventParams
.TableStyles.Add(gts)
.CaptionText = "Event Parameters"
End With
End Sub
Im Sure this is a standard question and one of those its easy if you know how.
Basically I am returning a dataset from sql server with five fields but only
want to display to columns in my datagrid populated from two fields from the
dataset
So ive
a) created a grid datagridstyle
b) Ive created a datatable to map the data from my dataset
c) Ive retrieved the data from sql server and copied the appropriate fields
to the grids datatable
It appears that all the styles are being ingnored and all the data from the
sql data set are being displayed
Any Ideas ?
Code included TIA
Private objEventParamDT As New DataTable("eventParamDT")
Private Sub populate_eventParams(ByVal p_nIdEvent As Integer)
Dim objDataSet As DataSet
Dim objEventParamRow, objDataRow As DataRow
Try
objDataSet = objEvent.getEventArgList(p_nIdEvent)
Call create_eventParamDataTable()
Call create_EventParamsGrid()
For Each objDataRow In objDataSet.Tables("results").Rows
objEventParamRow = objEventParamDT.NewRow
objEventParamRow("argSeq") = objDataRow("argSeq")
objEventParamRow("argDesc") = objDataRow("argDesc")
objEventParamDT.Rows.Add(objEventParamRow)
Next
With dgEventParams
.DataMember = "eventParamDT"
.DataSource = objEventParamDT
End With
MsgBox(dgEventParams.TableStyles.Item(0).GridColumnStyles.Item(0).HeaderText)
Catch ex As Exception
setStatus(ex.Message)
End Try
End Sub
Private Sub create_eventParamDataTable()
Dim nLeventId As New DataColumn("idLeventArg", GetType(Integer))
Dim nSeq As New DataColumn("argSeq", GetType(Integer))
Dim cArgDesc As New DataColumn("argDesc", GetType(String))
With objEventParamDT
' .Columns.Add(nLeventId)
.Columns.Add(nSeq)
.Columns.Add(cArgDesc)
End With
End Sub
Private Sub create_EventParamsGrid()
Dim gts As New DataGridTableStyle
dgEventParams.TableStyles.Clear()
gts.MappingName = "EventParamData"
' Set other properties.
gts.AlternatingBackColor = Color.LightGray
' Add a GridColumnStyle and set its MappingName
' to the name of a DataColumn in the DataTable.
' Set the HeaderText and Width properties.
' Dim txtEventId As New DataGridTextBoxColumn
' With txtEventId
' .MappingName = "idLeventArg"
' .HeaderText = ""
' .Width = 0
' .ReadOnly = True
' End With
'
Dim txtSeq As New DataGridTextBoxColumn
With txtSeq
.HeaderText = "Seq"
.MappingName = "argSeq"
.Width = 10
.ReadOnly = True
End With
gts.GridColumnStyles.Add(txtSeq)
Dim txtDesc As New DataGridTextBoxColumn
With txtDesc
.HeaderText = "Description"
.MappingName = "argDesc"
.Width = 200
.ReadOnly = True
End With
gts.GridColumnStyles.Add(txtDesc)
With dgEventParams
.TableStyles.Add(gts)
.CaptionText = "Event Parameters"
End With
End Sub