Link to home
Start Free TrialLog in
Avatar of ksfok
ksfok

asked on

Win form colordialog

I'm working on a winform datagrid that has a color field. How can I tie that color field to a color dialog to insert/update a color? (By the way I'm using Infragistics.) Thanks.
Avatar of ZeonFlash
ZeonFlash

There are some ambiguities that I'm confused over in your question.

1.  If you're using a WinForm datagrid and a WinForm color dialog...what from the Infragistics suite is being used?
2.  What do you mean by "color field"?  A cell that contains the name of a color?  A cell with a background that is the selected color?
3.  What are you inserting/updating when you select a color from the dialog?  A database entry?
Avatar of ksfok

ASKER

1) I'm using UltraGrid and UltraColorPicker.
2) Color field is a varchar(50) to store a color name like "Red"
3) Insert/Update a color name to the color column in the grid. The datatype is varchar(50).
Thanks.
You can set the UltraColorPicker control to be the EditorControl for the color column (it's easier to do in the Designer, but you can also do it in code).  

UltraGrid1.DisplayLayout.Bands(0).Columns("Color").EditorControl = UltraColorPicker1

When you drop-down the colorpicker in the cell, select a color, and close the drop-down, the .AfterCellListCloseUp event will fire, which is where you can call your Insert/Update command from.  The 'e' param object will have the cell that was just updated, where e.Cell.Text will be the name of the color selected, e.g. "Yellow".
Avatar of ksfok

ASKER

How can the color string entry be kept web format only e.g like "White", "Blue", "Red", or "yellow"...? Thanks.
I'm not sure that you can limit the selectable colors from the drop-down via methods in the control.  You can, however, check the color that was selected and alert the user to select another one if it's not a valid color name:

            If Color.FromName(e.Cell.Text).Equals(Color.Empty) Then
                  'Not a valid color name
            End If
Avatar of ksfok

ASKER

1) Can "Color.FromName(e.Cell.Text).Equals(Color.Empty) " be code as "Color.FromName(e.Cell.Text) = Color.Empty" ?
2)  I tested your sample and found entries in various custom/web or system format such as "Color [BlanchedAlmond]", "Color [A=999,B=999,C=999]", etc... how can we convert all color entry to a single plain web color name string like "White", "Blue", "Red", or "yellow" without other prefix, numbers, nor brackets?
Thanks.
Avatar of ksfok

ASKER

My project requires web and system colors with plain color name string entry only because the color string is read by another function to set color to a form layout. The original color{xxx] cannot be read by the formatting function. It should be taken as [xxx] as the color string. Can this be set in the color picker itself? I found it very hard to program this in the cell's events.
Please help. Thanks.
Avatar of ksfok

ASKER

Could someone please tell me how to stop with  a warning the color entry from the UltraColor Picker when user pick a ARGB color that doesn't have a name. Thanks.
Avatar of ksfok

ASKER

ZeonFlash

I'm almost done with the job. Here's what I got:

   Private Sub grdLayoutColumns_BeforeCellUpdate(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.BeforeCellUpdateEventArgs) Handles grdLayoutColumns.BeforeCellUpdate
        Dim strColor As String = e.NewValue.ToString
        If Not Color.FromName(strColor).Equals(Color.Empty) Then
            'Not a valid color name
            If Not IsKnownColor(strColor) Then
                MsgBox("This color is not available!")
                e.Cell.CancelUpdate()
            End If
        End If
    End Sub

But I found "e.Cell.CancelUpdate()" is not working. Would you know how to abort the cell's update?

Thanks for your help.
ASKER CERTIFIED SOLUTION
Avatar of ZeonFlash
ZeonFlash

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial