Datagrid, DataSet
-
Hi folks ! In the present code, we use a datagrid as a container to print data from a SQL database. The following gets data (via ODBC) in the SQL database and save it in a DATASET. Public Function GetDatasetGiveSql(ByVal sqlCmd As String) As DataSet Dim dataset As New DataSet odbcCmd.Connection.Close() odbcCmd = New Odbc.OdbcCommand(sqlCmd, odbcConnection) odbcAdapt = New Odbc.OdbcDataAdapter(odbcCmd) odbcCmd.Connection.Open() odbcAdapt.Fill(dataset) Return dataset End Function Elsewhere in the software, the software builds a query and sends it to the database like this: dsCommand = sql.GetDatasetGiveSql(cmd) DataGridCommand.SetDataBinding(dsCommand, "Table") As you can suspect, dsCommand is a DataSet and DataGridCommand is the DataGrid to update. Easy to date… OK. Question: --------- I want to have control on the background and foreground color of a cell based on some information like any people in this forum. I found many EXAMPLES with DataGridColumnStyle where the idea is to override the Paint method (aka: make a custom datagrid control). Yes, Perfect. I understand it BUT in this case… I DON’T CONTROL ANY COLUMN in the datagrid. It seems that the SetDataBinding() does everything by itself, it is magic. I did not find HOW to OVERRIDE the Paint() method of this datagrid. Maybe I don’t understand something ! :^) Danny Gilbert, enginneer Montréal, Canada -- modified at 13:44 Wednesday 19th April, 2006