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 : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

making a header cell editable in a gridcontrol

Thread ID:

Created:

Updated:

Platform:

Replies:

96498 Sep 16,2010 04:25 PM UTC Sep 15,2015 01:05 PM UTC WinForms 7
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On September 16, 2010 04:25 PM UTC

Is there some way to make a Header cell in a GridControl editable? I would like the user to be able to select the cell and edit, copy, and paste into it just as any other cell, (So that he can change column heading text.) but it should still look and behave like a header cell in other ways.


Nirmal Raja [Syncfusion]
Replied On September 20, 2010 12:17 PM UTC

Hi,

Thank you for your interest in Syncfusion products.

The PrepareViewStyleInfo event can be implemented in which you can specify the first row as the TextBox cell type. This can be provided to achieve the specified behavior.

Please refer the code below:
void gridControl1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
if (e.RowIndex == 0)
{
e.Style.CellType = "TextBox";
}
}


Let me know if you have any concern.

Regards,
Nirmal


Nirmal Raja [Syncfusion]
Replied On September 20, 2010 12:17 PM UTC

Hi,

Thank you for your interest in Syncfusion products.

The PrepareViewStyleInfo event can be implemented in which you can specify the first row as the TextBox cell type. This can be provided to achieve the specified behavior.

Please refer the code below:
void gridControl1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
if (e.RowIndex == 0)
{
e.Style.CellType = "TextBox";
}
}


Let me know if you have any concern.

Regards,
Nirmal


Administrator [Syncfusion]
Replied On September 20, 2010 01:14 PM UTC

I tried your suggestion, except that what you suggested changes the appearance of the entire row of header cells so that you no longer see the column borders. The header row just appears like a single long streak of the header color/pattern with no cell separations. Is there a way to determine which header cell was clicked and change only that cell to a textbox and then change it back when the cell loses focus or the enter key is pressed (or similar)?


Administrator [Syncfusion]
Replied On September 20, 2010 01:21 PM UTC

I tried your suggestion, but it doesn't work. I simply removes the cell borders in the header row. I need some way to allow the user to place the cursor in the header row cell and edit the text. I still need for him to be able to select the column by left clicking the column header, so the solution may need to be implemented via a contextmenu item where the user select a contextmenu item label "change header text" (or something) and the program changes the header cell to a text box and places the cursor at the beginning (or end) of the existing text and the user can then edit the text. (which would be entered as the cell's text when the user presses enter, or the cell loses focus, or something)

v/r
Jan



Rajadurai C [Syncfusion]
Replied On September 24, 2010 06:31 PM UTC

Hi Jan,

We regret for the delay caused.

The column header in GridControl can be set to editable through handling code similar to the following setting.

//to avoid trying to select columns when you click them
gridControl1.AllowSelection = GridSelectionFlags.Any & ~GridSelectionFlags.Column;
//add a little width
gridControl1.ColWidths[3] = 100;

gridControl1[0, 3].CellType = "TextBox"; //set the celltype to TextBox
gridControl1[0, 3].Text = "Some Text";
gridControl1[0, 3].CellAppearance = GridCellAppearance.Raised; //make it look like the rest of the headers


This setting makes the header of column 3 to be editable.

Regards,
Rajadurai


tttmack
Replied On September 11, 2015 09:36 PM UTC

Hello,

I would also like to have an editable header, but when I apply your suggested changes, it changes the background appearance of the cells in the header row to what looks like GridVisualStyles.SystemTheme. This causes the header to look completely different than the rest of my grid control since I am using GridVisualStyles.Office2007Blue

Is there a way to make the header cells editable while maintaining the theme that the control is set to?

Thanks,
Taylour



Adhikesevan Kothandaraman [Syncfusion]
Replied On September 15, 2015 01:05 PM UTC

Hi Taylor,

Thanks for your update.

The reported scenario can be achieved by setting the CellAppearance property and changing the CellType of the header cell as TextBox in QueryCellInfo event. Please make use of below code example,

Code Example:

void gridControl1_QueryCellInfo(object sender, Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs e)

{

   if(e.RowIndex == 0)

   {

       e.Style.CellType = GridCellTypeName.TextBox;

       e.Style.CellAppearance = GridCellAppearance.Raised;

       //setting the back color for the header cell.

       e.Style.BackColor = Color.LightBlue;

   }
}

Regards,
Adhi.


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.

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

;