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.

Virtual grid with custom controls

Thread ID:

Created:

Updated:

Platform:

Replies:

8695 Nov 17,2003 09:33 AM Dec 9,2003 02:11 AM Windows Forms 7
loading
Tags: GridControl
Christopher Peterson
Asked On November 17, 2003 09:33 AM

I am trying to create a virtual grid that will have custom controls. I doing so, I need to get the values from the controls in order to propagate the changes back to the external source. The SaveCellInfo event is not raised on changes to cells where CellType == "Control". I tried setting the Validated event for each individual control, but those event's aren't raised either. Any ideas? Code: // class-scoped variable: ------------------------- Syncfusion.Windows.Forms.Tools.DoubleTextBox dtb = new Syncfusion.Windows.Forms.Tools.DoubleTextBox(); // In constructor: ------------------ dtb.DoubleValue = initialValue; dtb.MinValue = minValue; dtb.MaxValue = maxValue; dtb.Validated += new System.EventHandler(handleDataChange); // In QueryCellInfo: -------------------- // if certain condition is true args.Style.CellType = "Control"; args.Style.Control = dtb; public void handleChange(object sender, System.EventArgs args) { // program never gets here }

Administrator [Syncfusion]
Replied On November 17, 2003 12:12 PM

To do this properly, I think you would need to derive your own cell control and manage things in the derived. You can see samples in our CellTypes sample folder (say, the slider control). It does take some code to tie into the grid control sharing architecture. But if you want to continue on the path you started using the Control cell type, you might be able to get things done using CurrentCellControlGainFocus and CurrentCellControlLostFocus.
string oldValue = "";
private void gridControl1_CurrentCellControlGotFocus(object sender, ControlEventArgs e)
{
	GridCurrentCell cc = this.gridControl1.CurrentCell;
	if(cc.RowIndex == 3 && cc.ColIndex == 2)
	{
		oldValue = dtb.Text;
	}
}

private void gridControl1_CurrentCellControlLostFocus(object sender, ControlEventArgs e)
{
	GridCurrentCell cc = this.gridControl1.CurrentCell;
	if(cc.RowIndex == 3 && cc.ColIndex == 2 && oldValue != dtb.Text)
	{
		Console.WriteLine("Special control changed");
	}
}

Christopher Peterson
Replied On November 18, 2003 01:30 PM

What I am trying to do is this: I have a virtual grid, let's simplify it and say it is 2 columns, linked to an external data structure. I have custom cell types modeled after the Slider cell example, call them "CustType1", "CustType2". I want the active row (or cell, I'm indifferent) of my grid to have cell types of "CustType1" and "CustType2". I want the rest of the cells to be of type "TextBox". I can't seem to do this. I'd like the cell types to be set on cell activation / deactivation since this would be the least overhead. I don't want to have to set the style for each cell on every draw since there will most likely be considerable setup time for customizing the cell type properties. I thought about using a combo of virtual grid / indexed grid, where I would ignore the current row in my query function and set the cell type in the activate/deactivate functions: private void gridQueryCellInfo(object sender, Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs args) { if (args.RowIndex > 0 && args.ColIndex > 0) { if (gridControl1.CurrentCell.RowIndex == args.RowIndex) args.Handled = false; ... } private void gridDeactivatedCell(object sender, Syncfusion.Windows.Forms.Grid.GridCurrentCellDeactivatedEventArgs args) { int row = gridControl1.CurrentCell.RowIndex; int col = gridControl1.CurrentCell.ColIndex; gridControl1[row, col].CellType = "TextBox"; } private void gridActivatedCell(object sender, System.EventArgs args) { int row = gridControl1.CurrentCell.RowIndex; int col = gridControl1.CurrentCell.ColIndex; gridControl1[row, col].CellType = col % 2 == 0 ? "CustType1" : "CustType2"; } However, this didn't work, the cells become detached from the grid and can't be edited, defeating the purpose of the custom control.

Administrator [Syncfusion]
Replied On November 18, 2003 01:44 PM

I think you will have to do the work in QueryCellInfo. If the e.RowIndex points to the current row, then set e.Style.CellType to you controls based on e.ColIndex. If you think the control will take too long initializing, you could cache the time consuming state information, and just retrieve it from the cached values. You control could listen to the grid.CurrentCellMoving event and if e.MoveToRow not equal e.MoveFromRow (meaning you are changing rows), then you could update your cached values. This way the time consuming part should only happen when you actually move the current row.

Christopher Peterson
Replied On November 19, 2003 08:16 AM

Are there going to be additional CellTypes in 2.0? I'd really like it if there was a "DoubleTextBox" CellType. I don't want to have to write wrapper a model base and renderer class when all I want to do is input a double value. Is there a way of mimicing the DoubleTextBox control with a MaskEdit cell type? (ie, accepts a fixed precision after the decimal point, variable number of digits prior to the decimal point, allows right padding of zeros for non-entered values, and turns red on negative values)?

Administrator [Syncfusion]
Replied On November 19, 2003 09:08 AM

There are no new celltypes in 2.0. This release is all about major new grouping functionality with only incremental changes and bug fixes in the other areas. Things like more cell types will be added in future releases. It probably would be easier to use a Currency cell than a make edit. You could set the CurrencySymbol to a space to hide it, an dthen you would have the formatting and coloring that you mentioned. You would probably still only want this for the active cell as using a lot of currecny cells can slow things down in the current code base. There was a work around posted for this in this thread. http://www.syncfusion.com/forums/message.asp?MessageID=6944

Ramachandran
Replied On December 8, 2003 10:32 PM

Hello, I am working with VB.NET.Iam a nebie.I need a Datagrid which has a multiline TextBox so that the values obtained from the database is editd in the DataGrid Itself.and also i need a combo box.How can i make it.Iam trying this for quite a long time but all my efforts are going futile.need u r help. Ramachandran > I am trying to create a virtual grid that will have custom controls. I doing so, I need to get the values from the controls in order to propagate the changes back to the external source. > > The SaveCellInfo event is not raised on changes to cells where CellType == "Control". I tried setting the Validated event for each individual control, but those event's aren't raised either. > > Any ideas? > > Code: > > // class-scoped variable: > ------------------------- > Syncfusion.Windows.Forms.Tools.DoubleTextBox dtb = new Syncfusion.Windows.Forms.Tools.DoubleTextBox(); > > > // In constructor: > ------------------ > dtb.DoubleValue = initialValue; > dtb.MinValue = minValue; > dtb.MaxValue = maxValue; > dtb.Validated += new System.EventHandler(handleDataChange); > > > // In QueryCellInfo: > -------------------- > // if certain condition is true > args.Style.CellType = "Control"; > args.Style.Control = dtb; > > > public void handleChange(object sender, System.EventArgs args) > { > // program never gets here > } >

Administrator [Syncfusion]
Replied On December 9, 2003 02:11 AM

Are you using a Syncfusion.Windows.Forms.Grid.GridDataBoundGridControl, or are you using the System.Windows.Forms.DataGrid that is part of the .NET framework. If you are using a DataGrid, this particular forum is for support of our GridDataBoundGrid, and not the framework''s DataGrid. Our Windows Forms FAQ does have a section of the dataGrid, http://www.syncfusion.com/FAQ/WinForms/default.asp#44, and it has code there that will let you put a ComboBox in a DataGrid cell. But it does take some coding. With the Syncfusion GridDataBoundGrid, you can have comboboxes and multiline text in cells without doing any coding other than possibly setting properties.

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.

;