Color column in sfdatagrid

Hi,

I need a column in an sfdatagrid that can be set as a color picker.
In a GridGroupingControl I can set a column celltype to ColorEdit.
Is there a way to do similar in an sfdatagrid?


Regards,
Rod

7 Replies 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team June 21, 2021 02:33 PM UTC

Hi Rod Schmitzer,

Thanks for the update.

Currently, we are analyzing your requirement of “Color column in sfdatagrid” We will validate and update you the details on or before June 23, 2021.

We appreciate your patience until then.

Regards,
Vijayarasan S


VS Vijayarasan Sivanandham Syncfusion Team June 23, 2021 04:04 PM UTC

Hi Rod Schmitzer,

Thank you for your patience. 

We are still working on this. We will update with further details on or before June 25, 2021. We appreciate your patience and understanding. 

Regards, 
Vijayarasan S 



VS Vijayarasan Sivanandham Syncfusion Team June 25, 2021 05:48 PM UTC

Hi Rod Schmitzer,

Thank you for your patience.

Your requirement can be achieved by creating the custom column in SfDataGrid. Based on provided information we have prepared the sample to achieve your requirement,
 
For more information related to Custom Column, please refer the KB documentation,

KB Link: https://www.syncfusion.com/kb/11754/how-to-add-the-button-and-text-in-gridtextcolumn-in-winforms-datagrid-sfdatagrid

https://www.syncfusion.com/kb/11573/how-to-add-the-radiobutton-column-in-winforms-datagrid-sfdatagrid

Please let us know if you have any concerns in this.

Regards,
Vijayarasan S




RS Rod Schmitzer June 29, 2021 06:16 AM UTC

Thanks you for the sample code. It works the way I need it to.

However, when I change the datasource to a datatable, I get an exception in the following line of code:

record1.GetType().GetProperty(mappingName).SetValue(record1, ColorConvert.ColorToString(SelectedColor, True))


I have uploaded my code which shows the problem.


Thanks,

Rod


Attachment: SyncfusionWinFormsApp2_c6793ce2.7z


VS Vijayarasan Sivanandham Syncfusion Team June 29, 2021 02:20 PM UTC

Hi Rod Schmitzer,

Thanks for the update.

You can update the selected color when Datatable collection binded in SfDataGrid by using the given below code snippet, 
Private Sub UpdateSummaryValues(ByVal rowIndex As Integer, ByVal columnIndex As Integer) 
                columnIndex = Me.TableControl.ResolveToGridVisibleColumnIndex(columnIndex) 
                If columnIndex < 0 Then 
                                Return 
                End If 
                Dim mappingName = DataGrid.Columns(columnIndex).MappingName 
                Dim recordIndex = Me.TableControl.ResolveToRecordIndex(rowIndex) 
                If recordIndex < 0 Then 
                                Return 
                End If 
                If DataGrid.View.TopLevelGroup IsNot Nothing Then 
                                Dim record = DataGrid.View.TopLevelGroup.DisplayElements(recordIndex) 
                                If Not record.IsRecords Then 
                                                Return 
                                End If 
                                Dim data = (TryCast(record, RecordEntry)).Data 
 
                                'below case using for DataTable Collection when dataGrid Grouped to set value 
                                TryCast(data, DataRowView).Row(mappingName) = ColorConvert.ColorToString(colorUI.SelectedColor, True) 
 
                                'below case using for ObservableCollection when dataGrid Grouped to set value 
                                'data.GetType().GetProperty(mappingName).SetValue(data, ColorConvert.ColorToString(colorUI.SelectedColor, True)) 
 
                Else 
                                Dim record1 = DataGrid.View.Records.GetItemAt(recordIndex) 
 
                                'below case using for DataTable Collection to update based on selected value 
                                TryCast(record1, DataRowView).Row(mappingName) = ColorConvert.ColorToString(SelectedColor, True) 
 
                                'below case using for ObservableCollection to set value 
                                'record1.GetType().GetProperty(mappingName).SetValue(record1, ColorConvert.ColorToString(SelectedColor, True)) 
                End If 
End Sub 

Please let us know if you have any concerns in this. 
 
Regards, 
Vijayarasan S 


Marked as answer

RS Rod Schmitzer June 30, 2021 05:29 AM UTC

That is perfect.

Thank you.



VS Vijayarasan Sivanandham Syncfusion Team June 30, 2021 06:14 AM UTC

Hi Rod Schmitzer,

We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you😊.

Regards,
Vijayarasan S


Loader.
Up arrow icon