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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Identifying the data column of a datasource in databound grid

Thread ID:

Created:

Updated:

Platform:

Replies:

15533 Jun 21,2004 06:17 PM UTC Jun 22,2004 02:35 PM UTC Windows Forms 6
loading
Tags: GridControl
Gulshan Khera
Asked On June 21, 2004 06:17 PM UTC

Hi Clay How can we identify the datacolumn which is attached to a particular cell of datbound grid. Thanks Gulshan

Administrator [Syncfusion]
Replied On June 21, 2004 07:03 PM UTC

Exactly how you do it depends upon whether you have explicitly added GridBoundColumns or not. Here are some snippets. int fieldNo = this.gridDataBoundGrid1.Binder.ColIndexToField(gridColumnIndex); //if you have explicitly added GridBoundColumns string colName = this.gridDataBoundGrid1.GridBoundColumns[fieldNo].MappingName; //if you haven''t explicitly added GridBoundColumns string colName = this.gridDataBoundGrid1.Binder.InternalColumns[fieldNo].MappingName;

Gulshan Khera
Replied On June 21, 2004 07:20 PM UTC

Clay Thanks for the reply. I was trying to do the same thing. but since i have to do it in PrepareViewStyleInfo event it slowing down evreything. Could yo please suggest any other way i can do it. thanks Gulshan

Gulshan Khera
Replied On June 21, 2004 07:25 PM UTC

Here is the code i was using int llColumnindex = this.gridDataBoundGrid1.Binder.ColIndexToField(e.ColIndex); string sName = this.gridDataBoundGrid1.Binder.InternalColumns[llColumnindex].MappingName; But i dont think its a good idea to use this code in PrepareViewStyleInfo. Thanks Gulshan

Administrator [Syncfusion]
Replied On June 21, 2004 08:11 PM UTC

You could create an array of the names so you could retrieve the names just by indexing the array with the e.ColIndex. You could use the above code to create the array in say, FormLoad. If you are allowing your user to move columns, you can handle the grid.Model.ColsMoved event, and then adjust the array (or recreate it).

Gulshan Khera
Replied On June 22, 2004 02:11 PM UTC

Clay Clay I have an array which has all the column names in it. Column name keep changing based on certain conditions. I need to paint the background color of the cell based on the column names last character. Here is the code by which i am trying to accomplish this. But its freezing the screen and not working the way i want it to work Please help!!!! if (e.RowIndex > 0 && e.ColIndex > 1) {string lsName = layoutItems[e.ColIndex].ToString(); int ik = lsName.IndexOf("-"); if(ik > 1){ int sLength = lsName.Length; string sDataType = lsName.Substring(sLength - 1 ,1); switch(sDataType) { case "1": e.Style.BackColor = Color.Azure; break; case "2": e.Style.BackColor = Color.AntiqueWhite; break; case "3": e.Style.BackColor = Color.LemonChiffon; break; case "4": e.Style.BackColor = Color.Gainsboro; break; } } } Thanks Gulshan I have this array which has all the column names in it. Column name keep chainging based on certain conditions. I need to paint the background color of the cell base don whats the column names last character is. here is the code by which i am trying to accomplish this. But its freezing the screen and not working the way i want it to work Please help!!!! if (e.RowIndex > 0 && e.ColIndex > 1) {string lsName = layoutItems[e.ColIndex].ToString(); int ik = lsName.IndexOf("-"); if(ik > 1){ int sLength = lsName.Length; string sDataType = lsName.Substring(sLength - 1 ,1); switch(sDataType) { case "1": e.Style.BackColor = Color.Azure; break; case "2": e.Style.BackColor = Color.AntiqueWhite; break; case "3": e.Style.BackColor = Color.LemonChiffon; break; case "4": e.Style.BackColor = Color.Gainsboro; break; } } } Thanks Gulshan

Administrator [Syncfusion]
Replied On June 22, 2004 02:35 PM UTC

Here is a sample that seems to work OK for me. ColNameSample_4393.zip

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;