PDA

Click to See Complete Forum and Search --> : Help setting datagrid properties


usa_dreamer2002
Jan 25th, 2005, 04:13 PM
Hi all, I hope you guys can help me with this issue.
i am creating a windows form and cannot set the properties for the colums.
e.g changing the colum name and alternating background color. I have attached some of the code to see if anyone may help me or tell me what I am doing wrong. The form doesnt give me any error but it does not change the property either.

Thanks in advance.

Private Function mainconn()
Dim checkcon As String
objconnection.Open()
a.SelectCommand = New OleDbCommand
a.SelectCommand.Connection = objconnection
'Selects the ID, Name, LastName etc fields on the table
a.SelectCommand.CommandText = _
" SELECT * from financial order by timein"
a.SelectCommand.CommandType = CommandType.Text
a.SelectCommand.ExecuteNonQuery()
a.Fill(ds, "financial")
objconnection.Close()
a = Nothing
objconnection = Nothing

'grid
DataGrid1.DataSource = ds
DataGrid1.DataMember = "financial"


DataGrid1.ColumnHeadersVisible = True
'declaring objects
Dim datagridtablestyle As New DataGridTableStyle
Dim columnstyle As New DataGridTextBoxColumn
'alternating color
datagridtablestyle.AlternatingBackColor = Color.WhiteSmoke
datagridtablestyle.MappingName = "Financial"

columnstyle.MappingName = "ID"
columnstyle.HeaderText = "Test ID"
'same settings for the rest of the fields
datagridtablestyle.GridColumnStyles.Add(columnstyle)
DataGrid1.TableStyles.Add(datagridtablestyle)

End Function

Pirate
Jan 26th, 2005, 11:47 PM
Not very sure why but DG may need to be refreshed and get replaced in the Form collection's object .