I want to recover the color of a color table and send it to the corresponding column for example when I re-open the application I load the colors in this as I am working with SQL 2012 and VB.NET component (DevExpress)
This way I have organized the color (column color is integer type): Column ID Color
In this way I send the columns to paint:
Private Sub V_quincenaII_RowCellClick(sender As Object, e As DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs) Handles V_quincenaII.RowCellClick Dim cd As New ColorDialog()
If e.Column.AbsoluteIndex = 1 Then
If cd.ShowDialog() = DialogResult.OK Then
V_quincenaII.Columns(1).AppearanceCell.BackColor = cd.Color
V_quincenaII.Columns(1).OptionsColumn.ReadOnly = True
registrarColor(cd.Color.ToArgb, 1, Me.cmbMes.EditValue, txtano.EditValue)
End If
End If .....
If e.Column.AbsoluteIndex = 16 Then If cd.ShowDialog() = DialogResult.OK Then V_quincenaII.Columns(16).AppearanceCell.BackColor = cd.Color V_quincenaII.Columns(16).OptionsColumn.ReadOnly = True registrarColor(cd.Color.ToArgb, 16, Me.cmbMes.EditValue, txtano.EditValue) End If End If
end sub
This way I send to save the color of that column:
Public Sub registrarColor(ByVal color As Integer, Columna As Integer, mes As Integer, ano As Integer) Try Using con As New SqlConnection(Rutina.CadenaConexion()) con.Open()
Dim query As String = "INSERT INTO Colores(Color,columna,id_mes,ano) VALUES (@color,@columna,@mes,@ano)"
Dim cmd As New SqlCommand(query, con)
cmd.Parameters.AddWithValue("@color", color)
cmd.Parameters.AddWithValue("@columna", Columna)
cmd.Parameters.AddWithValue("@mes", mes)
cmd.Parameters.AddWithValue("@ano", ano)
cmd.ExecuteNonQuery()
Me.G_quincenaII.DataSource = Deduccion.ListQuincena_II(Me.cmbMes.EditValue, txtano.EditValue)
MessageBox.Show("Color guardado!")
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
I am doing the actions in this order:
1) Open the application. Click on a cell to open the ColorDialog
. Select a color and close the dialog.
2) The selected color is applied to a column to which the cell is clicked. You are using the GridColumn.AppearanceCell.BackColor
property for this purpose.
3) Save the selected color to another table in your database.
4) Start the application again. The colors you have in that table should be applied to the columns.