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

Getting hidden cols value

If I hide a column by name grid1.Model.HideCols["id"] = true; And I have an event for double clicking on a cell (really only care about a row double click). How would I get the value for the hidden col when I know the row number and the column name?

6 Replies

AD Administrator Syncfusion Team January 21, 2003 09:12 AM UTC

Use the GridDataBoundGrid.Binder.NameToColIndex method to get the column index from the name. Then use this column index and your row index as indexers on the grid object. int col = this.grid1.Binder.NameToColIndex("id"); string strValue = this.grid1[row, col].Text; object objValue = this.grid1[row,col].CellValue;


RA Ranjit June 9, 2005 12:03 PM UTC

Clay, I am hiding Columns by calling: m_Grid.TableDescriptor.VisibleColumns.Remove("BackColor"); m_Grid.TableDescriptor.VisibleColumns.Remove("TextColor"); note: these are valid columns in my dataset I am setting the values in an Event by using the Style: GridTableCellStyleInfo style = m_Grid.TableModel[r, m_Grid.TableModel.NameToColIndex("BackColor") - 1]; style.CellValue = "1"; I am trying to Filter the records using : GridConditionalFormatDescriptor cfd_up = new GridConditionalFormatDescriptor("BackColor"); cfd_up.Expression = "[BackColor] = ''" + colorUIControl1.SelectedColor.ToArgb() + "''"; cfd_up.Appearance.AnyCell.BackColor = colorUIControl1.SelectedColor; td.ConditionalFormats.Add(cfd_up); The filter doesn''t return anything. However, if I choose not to hide these columns this code works fine. Thanks, Ranjit >Use the GridDataBoundGrid.Binder.NameToColIndex method to get the column index from the name. Then use this column index and your row index as indexers on the grid object. > > >int col = this.grid1.Binder.NameToColIndex("id"); >string strValue = this.grid1[row, col].Text; >object objValue = this.grid1[row,col].CellValue; >


AD Administrator Syncfusion Team June 9, 2005 01:05 PM UTC

Whether the columns are visible or not should not make a difference whether thay can be used in a Conditional format. Here is a sample that worked for me using a hidden column. http://www.syncfusion.com/Support/user/uploads/GGC_ExpressionField_c13cb1da.zip I suspect the problem has to do with the NameToColIndex call. You should check the values in teh stayle there to make sure you are operationing on teh style you think you are. Another way to try to set teh value is to get teh GridRecord and work with it. GridRecordRow rec = style.TableCellIdentity.DisplayElement as GridRecordRow; if(rec.ParentRecord != null) rec.ParentRecord.SetValue("Col0", 10000);


RA Ranjit June 9, 2005 01:24 PM UTC

Thanks your suggestion helped, but now there is a new issue. The code below, is called by an event raised by the user: *********************CODE BEGINS***************** private void HighlightRows_Clicked(object sender, EventArgs e) { GridTableDescriptor td = null; GridRangeInfo range = this.m_Grid.TableModel.Selections.Ranges.ActiveRange; if (!range.IsEmpty) { int icolInvisibleBackColor = m_Grid.TableModel.NameToColIndex("BackColor") - 1; for (int r = range.Top; r <= range.Bottom; r++) { GridTableCellStyleInfo style = m_Grid.TableModel[r, icolInvisibleBackColor]; GridRecordRow rec = style.TableCellIdentity.DisplayElement as GridRecordRow; if(rec.ParentRecord != null) rec.ParentRecord.SetValue("BackColor", colorUIControl1.SelectedColor.ToArgb().ToString()); //style.CellValue = colorUIControl1.SelectedColor.ToArgb().ToString(); //style.Text = colorUIControl1.SelectedColor.ToArgb().ToString(); } td = m_Grid.TableDescriptor; } else { GridRangeInfo inner_range = this.m_Grid.GetTableModel(m_sRelation[0]).Selections.Ranges.ActiveRange; int icolInvisibleBackColor = m_Grid.GetTableModel(m_sRelation[0]).NameToColIndex("BackColor") - 1; for (int r = inner_range.Top; r <= inner_range.Bottom; r++) { GridTableCellStyleInfo style = m_Grid.GetTableModel(m_sRelation[0])[r, icolInvisibleBackColor]; GridRecordRow rec = style.TableCellIdentity.DisplayElement as GridRecordRow; if(rec.ParentRecord != null) rec.ParentRecord.SetValue("BackColor", colorUIControl1.SelectedColor.ToArgb().ToString()); //style.CellValue = colorUIControl1.SelectedColor.ToArgb(); } td = m_Grid.GetTableDescriptor(m_sRelation[0]); } if(td != null) { GridConditionalFormatDescriptor cfd_up = new GridConditionalFormatDescriptor("BackColor"); cfd_up.Expression = "[BackColor] = ''" + colorUIControl1.SelectedColor.ToArgb() + "''"; cfd_up.Appearance.AnyCell.BackColor = colorUIControl1.SelectedColor; td.ConditionalFormats.Add(cfd_up); } } *********************CODE ENDS******************* Now, the grid used is a GGC, Steps followed are: 1. Highlight a childrow [works] 2. highlight a parent row [works] 3. Highlight a different child under the same parent row [does not work, the parent itself is getting repainted]. Thanks, Ranjit


AD Administrator Syncfusion Team June 9, 2005 02:06 PM UTC

If you are trying to use this.m_Grid.TableModel.Selections.Ranges.ActiveRange, this is the selection support inherited from GridControlBase. This support does not understand nested tables, so I do not think you will be able to get this working across nested tables. Exactly what are you trying to do? Can you use the Table.SelectedRecords support? This is the record selection support specific to GridGroupingCOntrol. You turn this on by setting grid.TableOptions.ListBoxSelectionMode to somthing other than None and setting grid.TableOptions.AllowSelection = GridSelectionFlags.None.


RA Ranjit June 10, 2005 04:42 AM UTC

Thanks a ton!!! What I was tryin to achieve was allow the user to highlight rows in a group and sub group with different colors in GGC. The SelectedRecords did the trick. Regards, Ranjit

Loader.
Live Chat Icon For mobile
Up arrow icon