Retrieve the color of a color table and send it to the corresponding column

1

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.

    
asked by Jose 12.10.2016 в 00:10
source

2 answers

0

The drawback is that you are not doing the SELECT of the information stored in the DB at the moment of "painting" the table; you should load or bring the columns stored in the database and perform a loop (cycle) at the time of "painting" the table with the values brought from the database.

    
answered by 13.10.2016 в 09:04
0

I solved it this way first I create an .xml file  Private _file As String="gridLayout1.xml"  That's where the color of the grid column keeps me.

Then I create a Function

Protected Overrides Sub OnLoad (ByVal and As EventArgs) V_Quincena.OptionsLayout.Columns.StoreAppearance = True         If File.Exists (_file) Then             V_Time **. RestoreLayoutFromXml ** (_ file)         End If     End Sub   that will validate me if the .xml file has color or not if it recovers it but it goes out and retrieves it with a property that receives the name .xml file as a parameter that is called .RestoreLayoutFromXml

Then I send it to save the color in the .xml file with a function

Protected Overrides Sub OnClosing (ByVal and As System.ComponentModel.CancelEventArgs)         V_Five. SaveLayoutToXml (_file)     End Sub

With a property that receives as a parameter the name of the .xml file that is called SaveLayoutToXml (_file)

Greetings.

    
answered by 13.10.2016 в 16:32