Home › Forums › WinForms controls › Xceed Grid for WinForms › How to add a button cell?
-
AuthorPosts
-
#15630 |
I want to add a button cell to manage each row,and every button’s text is “manage”
My Code:
Button btnBrowse = new Button();
btnBrowse.Text = “Manage”;
btnBrowse.Size = new Size(35, 20);
btnBrowse.Click += new EventHandler(btnBrowse_Click);
Column col=new Column();
col.Initialize(“Manage”, btnBrowse.GetType());
CellEditorManager btnEditor = new CellEditorManager(btnBrowse, “Text”, true, true);
CellViewerManager btnViewer = new CellViewerManager(btnBrowse, “Text”);
col.CellEditorManager = btnEditor;
col.CellViewerManager = btnViewer;
gridControl1.Columns.Add(col);In this way,the buttol cell will be add to the grid.but every button has no text !How can I do it?
thanks!Imported from legacy forums. Posted by handsomesun (had 2482 views)
BTW:How can I get the a cell value in currentrow?
Imported from legacy forums. Posted by handsomesun (had 329 views)
It is because you specify the Text property as property to use to get the editor value, which in this case does not make sense since it is a button, not a TextBox or something. Just set it to “”, and it will work.
Note that the to handle events on the editor, you should to it this way :
<code>
WinButton saveBtn = new WinButton( “Save” );
saveBtn.ButtonType = new ButtonType( ButtonBackgroundImageType.SpinUp, ButtonImageType.SpinUp );gridControl1.Columns[ “column1” ].CellEditorManager = new CellEditorManager( saveBtn, “”, true, true );
gridControl1.Columns[ “column1” ].CellViewerManager = new CellViewerManager( saveBtn, “” );
gridControl1.Columns[ “column1” ].CellEditorManager.ActivatingControl += new CellEditorEventHandler( CellEditorManager_ActivatingControl );
gridControl1.Columns[ “column1” ].CellEditorManager.DeactivatingControl += new CellEditorEventHandler( CellEditorManager_DeactivatingControl );void CellEditorManager_ActivatingControl( object sender, CellEditorEventArgs e )
{
( ( WinButton )e.Control ).Click += new EventHandler( Form1_Click );
}void CellEditorManager_DeactivatingControl( object sender, CellEditorEventArgs e )
{
( ( WinButton )e.Control ).Click -= new EventHandler( Form1_Click );
}void Form1_Click( object sender, EventArgs e )
{
WinButton button = sender as Button;
}</code>
To get the a cell value out of the current row, you need to cast it to the row type on which you are position at the time.
e.g.:
<code>
string value = ( ( Xceed.Grid.DataRow )gridControl1.CurrentRow).Cells[ “column1” ].Value.ToString();
</code>Imported from legacy forums. Posted by André (had 3677 views)
-
AuthorPosts
- You must be logged in to reply to this topic.