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
close icon

Identifying the data column of a datasource in databound grid

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

6 Replies

AD Administrator Syncfusion Team 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;


GK Gulshan Khera 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


GK Gulshan Khera 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


AD Administrator Syncfusion Team 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).


GK Gulshan Khera 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


AD Administrator Syncfusion Team June 22, 2004 02:35 PM UTC

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

Loader.
Live Chat Icon For mobile
Up arrow icon