We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Column Header Text in a GridControl

The GridControl by default sets the Column Header's at A, B, C, D etc. I want to give each column my own text such as CustId, AccountNo, CustomerName, AccountBalance.

How can this be done?

Thanks

6 Replies

HA haneefm Syncfusion Team April 18, 2007 05:18 PM UTC

Hi Greg,

You can try this code.

this.gridControl1.PopulateHeaders(GridRangeInfo.Cells(0,1,0,4) ,table);

Best regards,
Haneef


GG Greg Goodall April 18, 2007 06:28 PM UTC

I am using the code below but it only changes the header of the first column from "A" to "Value".

Dim strHeaders() As String
strHeaders = New String() {"CustId", "AccountNo", "CustomerName", "AccountBalance"}
Me.gridMatrixLines.PopulateHeaders(GridRangeInfo.Cells(0, 1, 0, 4), strHeaders)

Do you have an example VB project that I could look at?

Thanks


HA haneefm Syncfusion Team April 18, 2007 07:03 PM UTC

Hi Greg,

You can try this code.

Dim dt As DataTable = New DataTable
dt.Columns.Add("CustId")
dt.Columns.Add("AccountNo")
dt.Columns.Add("CustomerName")
dt.Columns.Add("AccountBalance")
Dim dr As DataRow = dt.NewRow()
dt.Rows.Add(dr)
dt.AcceptChanges()

Me.GridControl1.PopulateHeaders(Syncfusion.Windows.Forms.Grid.GridRangeInfo.Cells(0, 1, 0, 5), dt)

Best regards,
Haneef


GG Greg Goodall April 18, 2007 08:34 PM UTC

This worked perfectly. Now I have to figure out how to set the width of each column based upon the length of the text.

Thanks.


RA ranjumalhotra March 28, 2008 09:53 AM UTC

Hi,

I have retained the deafult column headers.However if i try to retrieve the column header text by saying
string str=this.GridControl1[0,1].Text;
it does not provide any value.

please help.

Thanks
ranju malhotra

>The GridControl by default sets the Column Header's at A, B, C, D etc. I want to give each column my own text such as CustId, AccountNo, CustomerName, AccountBalance.

How can this be done?

Thanks



AD Administrator Syncfusion Team March 31, 2008 09:40 AM UTC


Hi Greg,

Thanks for the interest in Syncfusion products.

You can set the Column header text of the gird from the Text properties and also you can retrieve the column header by saving to a string. Please refer the following code snippet.


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GridControl1(0, 1).Text = "CustId"
GridControl1(0, 2).Text = "AccountNo"
GridControl1(0, 3).Text = "CustomerName"
GridControl1(0, 4).Text = "AccountBalance"
GridControl1.Model.ColWidths.ResizeToFit(Syncfusion.Windows.Forms.Grid.GridRangeInfo.Col(1))
GridControl1.Model.ColWidths.ResizeToFit(Syncfusion.Windows.Forms.Grid.GridRangeInfo.Col(2))
GridControl1.Model.ColWidths.ResizeToFit(Syncfusion.Windows.Forms.Grid.GridRangeInfo.Col(3))
GridControl1.Model.ColWidths.ResizeToFit(Syncfusion.Windows.Forms.Grid.GridRangeInfo.Col(4))
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str1 As String = Me.GridControl1(0, 1).Text
Dim str2 As String = Me.GridControl1(0, 2).Text
Dim str3 As String = Me.GridControl1(0, 3).Text
Dim str4 As String = Me.GridControl1(0, 4).Text
MessageBox.Show("Col1: " + str1 + " Col2:" + str2 + " Col3:" + str3 + " Col4 : " + str4)
End Sub


Please refer the sample in the below link that illustrates the above.

http://websamples.syncfusion.com/samples/Grid.Windows/F59616/main.htm

Please let me know if this is not what you needed.

Regards,
Asem.


Loader.
Live Chat Icon For mobile
Up arrow icon