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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How can I make the header column selectable.

Thread ID:

Created:

Updated:

Platform:

Replies:

56767 Feb 20,2007 06:18 PM UTC Feb 21,2007 10:27 PM UTC WinForms 3
loading
Tags: GridControl
James Blibo
Asked On February 20, 2007 06:18 PM UTC

I want to be able to select a header column. I have disable sorting for specific header columns by using...

void gridGroupingControl1_TableControlQueryAllowSortColumn(object sender, GridQueryAllowSortColumnEventArgs e)
{
if (e.Column.Name = "col1")
e.AllowSort = false;
}

However, I want to be able to select the header column or display a visible indicator that the header column is selected when the user click on a header column.

Administrator [Syncfusion]
Replied On February 20, 2007 08:55 PM UTC

Hi James,

There are two types of selection modes available for GridGroupingControl. One is inherited from the GridControlBase and the other is record based selection, that is specfic to the GridGroupingControl. Refer to the KnowledgeBase(KB) article link below for more details on this.

http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=344

However, neither of the above mentioned selection modes will allow you to select columns. But TableControlCellClick event can be handled to do this. Below is the code snippet.

this.gridGroupingControl1.TableOptions.AllowSelection = GridSelectionFlags.Any; // Form_Load
ArrayList selectedColumns = new ArrayList();
private void gridGroupingControl1_TableControlCellClick(object sender, GridTableControlCellClickEventArgs e)
{
GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex,e.Inner.ColIndex)
if(style.TableCellIdentity.TableCellType == GridTableCellType.ColumnHeaderCell)
{
GridRangeInfo range = GridRangeInfo.Col(e.Inner.ColIndex);
range = range.ExpandRange(2, e.Inner.ColIndex, e.TableControl.Model.RowCount, e.Inner.ColIndex);
if(e.TableControl.Selections.Ranges.AnyRangeContains(range))
{
e.TableControl.Selections.SelectRange(range, false);
selectedColumns.Remove(style.TableCellIdentity.Column.Name);
}
else
{
e.TableControl.Selections.SelectRange(range, true);
selectedColumns.Add(style.TableCellIdentity.Column.Name);
}
}
}

Here is a sample
http://www.syncfusion.com/Support/user/uploads/GGC_CompareData_d2e886a8.zip

To select a column programatically use the code below.
// selects first column...
this.gridGroupingControl1.TableModel.Selections.Add(GridRangeInfo.Cells(2,1,this.gridGroupingControl1.TableModel.RowCount, 1));

Best regards,
Haneef

James Blibo
Replied On February 21, 2007 12:41 AM UTC

Actually I was looking for something else... I just want to draw a border around the column header to indicate that it is selected. I want to move the border from around the active cell and apply it to the column header.

Administrator [Syncfusion]
Replied On February 21, 2007 10:27 PM UTC

Hi James,

One way you can do this by handling the TableControlDrawCell event of the grid and draw the black rectangle around the column header cell usng the e.Inner.Graphics.DrawRectangle method from the GridTableControlDrawCellEventArgs. Please refer to the attached sample and let me know if this helps.

private void gridGroupingControl1_TableControlDrawCell(object sender, GridTableControlDrawCellEventArgs e)
{
GridTableCellStyleInfo style = e.Inner.Style as GridTableCellStyleInfo;
if( style.TableCellIdentity.TableCellType == GridTableCellType.ColumnHeaderCell )
{
if( e.TableControl.Model.SelectedRanges.AnyRangeIntersects(GridRangeInfo.Col(e.Inner.ColIndex)))
{
Rectangle rect = e.Inner.Bounds;
rect.Inflate(-2,-2);
e.Inner.Renderer.Draw(e.Inner.Graphics,e.Inner.Bounds,e.Inner.RowIndex,e.Inner.ColIndex,e.Inner.Style);

Pen p = new Pen(Color.Black,3f);
e.Inner.Graphics.DrawRectangle(p,rect);
e.Inner.Cancel = true;
}
}
}

Sample : GGCDrawCell.zip

Best regards,
Haneef

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.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

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

;