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 Style

Hi! I'ld like to set a format (or alignment, or...) to a column. (grid.ColStyles[3].Format = "0.000";) If i am working with an virual grid, this does not work, because the parameter e of the method grid_QueryCellInfo gives me an object, in which nothing of these informations are stored in. It is also not possible to set a hole style (e.Style = grid.ColStyles[3]). So what can I do, if I don't want to set every single property in QueryCellInfo? Thanks for help in advance Barbara

5 Replies

AD Administrator Syncfusion Team March 31, 2003 11:20 AM UTC

Setting ColStyles probably should work for you. Make sure in your SaveCellInfo, you are only setting e.Handled when e.ColIndex and e.RowIndex are greater than zero. If you always set it, then your Colstyles will not get saved when you set them in code. (Note, our VirtualGridTutorial Sample does always set e.Handled in SaveCellInfo, but it does not try to use ColStyles either. We will change that....)

BA Barbara Arz March 31, 2003 12:49 PM UTC

Well, I tried it out: It is not necessary to implement SaveCellInfo. But it works if I set e.Handled = true; in QueryCellInfo if row and column are > 0. But what will happen, if I change the values of row=0 or col=0? Beside this: for what do I have to set e.Handled = true? It also works without doing that. Here I found another funny behavior: The text will be correctly written to the cells, but the color of the text will be set for all cells in the grid. Is this a bug or a feature? grid_QueryCellInfo(...) { if (e.RowIndex>4 && e.ColIndex >6 ) { e.Style.CellValue = "gg"; e.Style.TextColor = System.Drawing.Color.DarkKhaki; }

AD Administrator Syncfusion Team March 31, 2003 01:54 PM UTC

Checking for e.RowIndex > -1 and e.ColIndex > -1 will work. When the e.RowIndex is passed in as -1, the style that is being populated is the ColStyles[e.ColIndex]. When e.ColIndex is -1, the style being populated is the RowStyles[e.RowIndex]. So, if you want to set e.Style for e.RowIndex = == 0 or e.ColIndex == 0, then that should not affect these ColStyles request. Setting e.Handled = true tells the grid not to look further for any style information. For example, if you set e.handled = true for e.RowCol==-1, then any ColStyles you tried to save with an indexer will be skipped. If you are in a GridDataBoundGrid, then trying to get the value from the datasource would not happen if you set e.handled = true. I tried you code snippet in the VirtGridTutorial and did not see the problem you described with the TextColor. Can you post a sample project showing the problem?

BA Barbara Arz April 1, 2003 05:38 AM UTC

Hi! Well it works now! Attached I send you the sample with the textcolor problem. For what stands RowIndex=-1? Best regards Barbara

AD Administrator Syncfusion Team April 1, 2003 11:07 AM UTC

> Hi! > Well it works now! > > Attached I send you the sample with the textcolor problem. > For what stands RowIndex=-1? > > Best regards > Barbara Barbara, the -1 indicates that QueryCellInfo asks for column, row or table style. Row -1, Col -1 means table style. Row -1, Col >= 0 means column style. Row >= 0, Col -1 means row style. In your sample code: private void gridControl1_QueryCellInfo(object sender, Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs e) { if (e.RowIndex<=_values.GetUpperBound(0) && e.RowIndex>=0 && e.ColIndex <= _values.GetUpperBound(1) && e.ColIndex>=0 ) { e.Style.CellValue = _values[e.RowIndex, e.ColIndex]; } else { e.Style.CellValue = "gg"; e.Style.TextColor = System.Drawing.Color.DarkKhaki; } if (e.ColIndex >= 0 && e.RowIndex >= 0) { e.Handled = true; } } The else branch is excecuted for TableStyle, row styles and column styles. Therefore all cells will be DarkKhaki. Best would be to add at the beginning of your handler following code: if (e.ColIndex < 0 || e.RowIndex < 0) { // do nothing ... return; } Stefan

Live Chat Icon For mobile
Up arrow icon