Tag Property

Hi, I'm using sfDataGrid (winforms vb 2019) and I have two questions.

1st
I need to store a custom object into Column definition.
Is there a property for GridColumn where I can store object data? I'm looking for something like TAG property.

2nd
Is there a way to get column index by column name? I know MappingName and HeaderText of a specific column and I need to get the index of that column.

Thanks in advance



1 Reply 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team August 8, 2022 04:51 PM UTC

Hi Diego,

Please find answer for your queries below

Queries

Solutions

 

I need to store a custom object into Column definition.

Is there a property for GridColumn where I can store object data? I'm looking for something like TAG property.

 


GridColumn does not contain property to store the object data.

However, your requirement to store the store object data in property in GridColumn can be achieved by overriding the predefined column types in SfDataGrid. Please refer to the below code snippet,

 

Me.sfDataGrid1.Columns.Add(New GridTextColumnExt() With

{

                                                          .MappingName = "OrderID",

                                                          .CustomObject = "DefineCustomObject",

                                                          .HeaderText = "Order ID"

})

 

             

Public Class GridTextColumnExt

        Inherits GridTextColumn

 

        Private customObject_Renamed As Object

 

                             Public Property CustomObject() As Object

                                           Get

                                                          Return customObject_Renamed

                                           End Get

 

                                           Set(ByVal value As Object)

                                                          customObject_Renamed = value

                                           End Set

                             End Property

 

End Class

 

UG Link: https://help.syncfusion.com/windowsforms/datagrid/columntypes?cs-save-lang=1&cs-lang=vb#creating-column-from-existing-column

 

 

 

Is there a way to get column index by column name? I know MappingName and HeaderText of a specific column and I need to get the index of that column.

 


Your requirement to get column index by column name in SfDataGrid can be achieved by passing the GridColumn like below mentioned code snippet,

 

Private Sub btnGetIndexofColumn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnGetIndexofColumn.Click

              'here get the Column by passing MappingName of Column

              Dim getColumn = sfDataGrid1.Columns("CustomerName")

              'here pass that column to get ColumnIndex

              Dim ColumnIndex = sfDataGrid1.Columns.IndexOf(getColumn)

 

              MessageBox.Show("Column Index :" & ColumnIndex)

End Sub

 

UG Link: https://help.syncfusion.com/windowsforms/datagrid/columns?cs-save-lang=1&cs-lang=vb#accessing-column

 


Please find the sample in the attachment and let us know if you have any concerns in this.


Regards,

Vijayarasan S

If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Attachment: SfDataGridDemo_c8803b51.zip

Marked as answer
Loader.
Up arrow icon