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

Setting Column Headers in Databound Grid - No success

I am trying to set the column headers for a databound grid using gridName[0, 1].Text = "MyColumnHeader"; in C#. It works for gridName[0,0].Text = "Test"; Is this because 0,0 is not databound? If so, what do I need to do to set it for a databound grid? I am on version I think (the lates download patch). I can read the original text though and put it in a messagebox. Thanks, Knut

3 Replies

KV Knut Vonheim February 23, 2003 10:24 PM UTC

I have also tried gridName.GridBoundColumns["ColumnName"].HeaderText = "NewHeader"; gridName.GridBoundColumns[1].HeaderText = "NewHeader"; but get an error message at run time saying: "An unhandled exception of type 'System.NullReferenceException' occurred in ucscheduledaycardio.dll Additional information: Object reference not set to an instance of an object." The problem is that the object and the data that go with it is displayed on the screen. I even tried to put this on a button just to make sure. No luck! The code in the previous posting does not cause an error. Thanks again! Knut

AD Administrator Syncfusion Team February 23, 2003 10:50 PM UTC

You do need to set the header text through the GridBoundColumns. But if you are getting thoses null reference exceptions, it suggests that you did not add any GridBoundColumns to your GridDataBoundGrid. In such a case, you should use the Binder.InternalColumns that are added for you when you don't add any. So, try code such as gridName.Binder.InternalColumns[1].HeaderText = "NewHeader";

KV Knut Vonheim February 24, 2003 07:19 PM UTC

Clay, that worked! I must have been mistaken when I thought the GridBoundColumns were added if I bound a column to a dataset column in the designer. Wish the documentation was a little better, but you and this forum are great alternatives! Thanks again Clay! Cheers, Knut

Live Chat Icon For mobile
Up arrow icon