Articles in this section
Category / Section

How to get the tags when the style.Tag is set through PrepareViewStyleInfo or QueryCellInfo events?

2 mins read

When a tag of a cell style is set through ‘’ event, that tag value cannot be retrieved using `this.grid[0,1].Tag`. Instead, you can make use of GetView() method in WinForms GridControl for retrieving the tag in such cases.

C#:

  this.gridControl1.PrepareViewStyleInfo += gridControl1_PrepareViewStyleInfo;
}
private void gridControl1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
    if (e.RowIndex == 0 && e.ColIndex == 1)
    {
        e.Style.Text = "Header1";
        e.Style.Tag = "Test tag";
    }
}
private void button1_Click(object sender, EventArgs e)
{
    object obj = new object();
    obj = this.gridControl1.GetViewStyleInfo(0, 1).Tag;
    MessageBox.Show(obj.ToString());
}

 

VB:

Private Me.gridControl1.PrepareViewStyleInfo += AddressOf gridControl1_PrepareViewStyleInfo
}
Private Sub gridControl1_PrepareViewStyleInfo(ByVal sender As Object, ByVal e As GridPrepareViewStyleInfoEventArgs)
 If e.RowIndex = 0 AndAlso e.ColIndex = 1 Then
  e.Style.Text = "Header1"
  e.Style.Tag = "Test tag"
 End If
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
 Dim obj As New Object()
 obj = Me.gridControl1.GetViewStyleInfo(0, 1).Tag
 MessageBox.Show(obj.ToString())
End Sub
 

 

Showing tag in Grid control

Samples:

C#: Set and Get a tag

VB: Set and Get a tag

Conclusion

I hope you enjoyed learning about how to assign Column names to the Grid Controls, besides the normally assigned numbered headers.

You can refer to our WinForms GridControl’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms GridControl documentation to understand how to present and manipulate data.

For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms GridControl and other WinForms components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

 

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied