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.

RowStyles[index].Borders is not working in Forms.Grid.GridControl

Thread ID:

Created:

Updated:

Platform:

Replies:

27259 Apr 8,2005 07:22 AM Apr 8,2005 10:56 AM Windows Forms 3
loading
Tags: GridControl
Dilek Kayhan
Asked On April 8, 2005 07:22 AM

I have a problem where I CANNOT set the Row borders in a Virtual Grid(Syncfusion.Windows.Forms.Grid.GridControl), I CAN set the Columns borders but this fails for the rows. The code that is attached here is the Virtual Grid sample, that is slightly modified. I have modified the code in gridControl1_SelectionChanged method basically every time I select a row or a column. I am trying to set the border for the column or the row. I am not sure what I am doing wrong or if this a bug in the underlying code. CODE private void gridControl1_SelectionChanged(object sender, GridSelectionChangedEventArgs e) { GridBorder _thickBorder = new GridBorder(GridBorderStyle.Solid, Color.Black ,GridBorderWeight.Thick); GridBorder redBorder = new GridBorder(GridBorderStyle.Solid, Color.Red ,GridBorderWeight.Thick); GridRangeInfoList cols = this.gridControl1.Selections.GetSelectedCols(true,false); //WORKSSSS foreach(GridRangeInfo i in cols) { int index = i.Left; this.gridControl1.ColStyles[index].Borders.Bottom = _thickBord er; this.gridControl1.ColStyles[index].TextColor = Color.Blue; } ///////PROBLEMATIC BIT!///////////////////// GridRangeInfoList rows = this.gridControl1.Selections.GetSelectedRows(true,false); if(rows !=null) { foreach(GridRangeInfo i in rows) { this.gridControl1.RowStyles[i.Top].Borders.Bottom = redBorder; } } ENTIRE CODE: using System.Xml; using System.Xml.Serialization; using System.IO; namespace VirtualGrid { using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using Syncfusion.Windows.Forms.Grid; us ing Syncfusion.Windows.Forms; using Syncfusion.Drawing; /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private Syncfusion.Windows.Forms.Grid.GridControl gridControl1; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); //turn off D&D support gridControl1.ControllerOptions = GridControllerOptions.All & (~GridControllerOptions.OleDataSource); gridControl1.ResetVolatileData(); gridControl1.QueryCellInfo += new GridQueryCellInfoEventHandler(GridQueryCellInfo); //-0-gridControl1.QueryRowCount += new GridRowColCountEventHandler(GridQueryRowCount); //--gridControl1.QueryCoveredRange+=new GridQueryCoveredRangeEventHandler( gridControl1_QueryCoveredRange); //--gridControl1.QueryRowHeight += new GridRowColSizeEventHandler(GridQueryRowHeight); gridControl1.ColWidths[0] += 10; this.gridControl1.RowHeights[0] +=5; gridControl1.SelectionChanged+=new GridSelectionChangedEventHandler(gridControl1_SelectionChanged); for(int i=0; i<100; i++) gridControl1.Cols.InsertRange(i,1); for(int i=0; i<100; i++) gridControl1.Rows.InsertRange(i,1); // // TODO: Add any constructor code after InitializeComponent call // } /* void GridQueryRowCount(object sender, GridRowColCountEventArgs e) { e.Count = 30000; e.Handled = true; } */ void GridQueryCellInfo(object sender, GridQueryCellInfoEventArgs e) { if (e.RowIndex > 0) { if (e.ColIndex > 0) { if (e.ColIndex != 2) e.Style.CellValue = e.RowIndex.ToString() + "/" + e.ColIndex .ToString(); if (e.RowIndex % 2 == 0) { // e.Style.Interior = new BrushInfo(Color.FromArgb(0xED, 0xF0, 0xF7)); e.Style.VerticalAlignment = GridVerticalAlignment.Bottom; } else //e.Style.Interior = new BrushInfo(Color.FromArgb(0x91, 0xBB, 0xB8)); /* if (e.ColIndex == 2) { if (e.RowIndex %2 == 0) e.Style.CellType = "PushButton"; else e.Style.CellType = "DropDownGrid"; e.Style.Description = "Click"; } else e.Style.CellType = "Static"; */ if (e.RowIndex % 4 == 0) e.Style.Borders.Bottom = new GridBorder(GridBorderStyle.Solid, Color.Orange, GridBorderWeight.Medium); } e.Handled = true; } } void GridQueryRowHeight(object sender, GridRowColSizeEventArgs e) { if (e.Index % 2 == 0) { e.Size 3d 25; e.Handled = true; } } void GridQueryCoveredRange(object sender, GridQueryCoveredRangeEventArgs e) { if (e.RowIndex % 2 == 1 && e.ColIndex >= 1 && e.ColIndex <= 3) { e.Range = GridRangeInfo.Cells(e.RowIndex, 1, e.ColIndex, 3); e.Handled = true; } } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { gridControl1.QueryCellInfo -= new GridQueryCellInfoEventHandler(GridQueryCellInfo); //--gridControl1.QueryRowCount -= new GridRowColCountEventHandler(GridQueryRowCount); gridControl1.QueryCoveredRange -= new GridQueryCoveredRangeEventHandler(GridQueryCoveredRange); gridControl1.QueryRowHeight -= new GridRowColSizeEventHandler(GridQueryRowHeight); if (components != null) { components.Dispose(); }< br> } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.gridControl1 = new Syncfusion.Windows.Forms.Grid.GridControl(); ((System.ComponentModel.ISupportInitialize)(this.gridControl1)).BeginInit(); this.SuspendLayout(); // // gridControl1 // this.gridControl1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right); this.gridControl1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.gridControl1.Bounds = new System.Drawing.Rectangle(24, 24, 504, 320); this.gridControl1.ColCount = 100; this.gridCo ntrol1.RowCount = 100; this.gridControl1.DefaultColWidth = 65; this.gridControl1.DefaultRowHeight = 17; this.gridControl1.DefaultGridBorderStyle = Syncfusion.Windows.Forms.Grid.GridBorderStyle.Dotted; this.gridControl1.Dock = System.Windows.Forms.DockStyle.None; this.gridControl1.HorizontalThumbTrack = true; this.gridControl1.Location = new System.Drawing.Point(24, 24); this.gridControl1.Name = "gridControl1"; this.gridControl1.Size = new System.Drawing.Size(504, 320); this.gridControl1.TabIndex = 1; this.gridControl1.Text = "gridControl1"; this.gridControl1.ThemesEnabled = true; this.gridControl1.VerticalThumbTrack = true; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(560, 374); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.grid Control1}); this.Name = "Form1"; this.Text = "Form1"; ((System.ComponentModel.ISupportInitialize)(this.gridControl1)).EndInit(); this.ResumeLayout(false); } #endregion /// /// The main entry point for the application. /// [STAThread] public static void Main() { Application.Run(new Form1()); } private void gridControl1_SelectionChanged(object sender, GridSelectionChangedEventArgs e) { GridBorder _thickBorder = new GridBorder(GridBorderStyle.Solid, Color.Black ,GridBorderWeight.Thick); GridBorder redBorder = new GridBorder(GridBorderStyle.Solid, Color.Red ,GridBorderWeight.Thick); GridRangeInfoList cols = this.gridControl1.Selections.GetSelectedCols(true,false); foreach(GridRangeInfo i in cols) { int index = i.Left; this.gridControl1.ColStyles[index].Borders.Bottom = _thickBord er; this.gridControl1.ColStyles[index].TextColor = Color.Blue; } ///////PROBLEMATIC BIT!///////////////////// GridRangeInfoList rows = this.gridControl1.Selections.GetSelectedRows(true,false); if(rows !=null) { foreach(GridRangeInfo i in rows) { this.gridControl1.RowStyles[i.Top].Borders.Bottom = redBorder; } } } private void gridControl1_QueryCoveredRange(object sender, GridQueryCoveredRangeEventArgs e) { if (e.RowIndex % 2 == 1 && e.ColIndex >= 1 && e.ColIndex <= 3) { e.Range = GridRangeInfo.Cells(e.RowIndex, 1, e.ColIndex, 3); e.Handled = true; } } } }

Administrator [Syncfusion]
Replied On April 8, 2005 09:21 AM

In a virtual grid, there are no rowstyles allocated unless you explicitly set grid.RowCount = xxx. But if you do, this sort of defeats the purpose of trying to avoid allocating objects for every row. Instead, what you can do is to provide the row style in QueryCellInfo. When e.ColIndex == 0 and e.RowIndex > 0, then the e.Style object refers to the row style for the row at e.RowIndex. So, try setting these Borders in QueryCellInfo to see if that works for you.

Dilek Kayhan
Replied On April 8, 2005 09:51 AM

Hi Clay Thanks for your quick answer Well I do set the RowCount as well as ColAccount.. as you can see in the code It is set to 100 (this.gridControl1.ColCount = 100;this.gridCo ntrol1.RowCount = 100;) in InitializeComponent() method. If I can set the ColStyles, why cannot I set the RowStyles? YES: I can set the RowStyles in the CellInfo method. But I have to have my own model to remember it all.. want to avoid this.. I believe we have been told by one of the syncfusion guys that setting the RowCount and ColCount would make things quicker rather than hooking up with the RowAccount and ColAccount methods. Is this correct? We have a structure where row/col counts do not change. I wanted avoid to have a style model on top of this grid, rather than using the Grids RowStyles, ColStyles and only provide the Cell.Text in the CellInfo method. But I believe my understanding of Virtual Grid is maybe wrong.. And your documentation is not really sufficient about this to clarify my doubts.. Is there a way I can use the RowStyles,ColStyles data and only provide the cellvalues at The CellInfo.. ? What do you mean if I set the RowCount and ColCount it defeats the purpose? Thanks Clay Dilek >In a virtual grid, there are no rowstyles allocated unless you explicitly set grid.RowCount = xxx. But if you do, this sort of defeats the purpose of trying to avoid allocating objects for every row. > >Instead, what you can do is to provide the row style in QueryCellInfo. When e.ColIndex == 0 and e.RowIndex > 0, then the e.Style object refers to the row style for the row at e.RowIndex. So, try setting these Borders in QueryCellInfo to see if that works for you.

Administrator [Syncfusion]
Replied On April 8, 2005 10:56 AM

You can set grid.RowCount. This will allocate objects for rowstyles. It will not likely be a problem for rowcount = 100, but it may if you are trying to set rowcount = 1000000000. One use of a virtual grid is to handle large amounts of data. It really can only do this if the rowcount/colcount is provided dynamically, just like the data. If your reason for using a virtual grid is not to handle a large amount of data, then setting the rowcount and colcount can simplify things like you should be able to set RowStyles from teh grid''s cache instead of providing them dynamically ffrom your cache. I think the reason the rowstyle is not being applied is because of the e.Handled = true; in your QueryCellInfo code. Try commenting it out. (It is preventing the rowstyle from being applied.).

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.

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.

;