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.
Syncfusion Feedback

Changing the behaviour of TextBox cells in DB Grid

Thread ID:

Created:

Updated:

Platform:

Replies:

17816 Aug 17,2004 07:24 PM UTC Aug 21,2004 11:55 AM UTC Windows Forms 5
loading
Tags: GridControl
Jeck
Asked On August 17, 2004 07:24 PM UTC

Hello, I''m trying to code the following functionality: Certain cells in the databound grid should contain editable values that are representations of some other values in the datasource. Example: column 1 should contain value of type "weight". While on the screen it would be displayed and edited as kgs, pounds, ounces etc; in datasource I want it to stay in kgs all the time. column 2 has "linear dimension", that should be displayed/edited in meters, feet, yards, depending on configuration, but again, datasource should store it all in meters. We already have a library of parsers/converters/validators that make it simple to convert any text value with specified units to standard units, and vice versa. What I''m trying to figure out is where do I plug in these parsers and formatters? Creating a new GridMyTextBoxCellModel with a new CellRendered seems like overkill - it''s still just a TextBox!.. Or can I inherit from GridTextBoxCellModel without creating my own renderer? Thanks in advance!

Administrator [Syncfusion]
Replied On August 17, 2004 08:57 PM UTC

You can use the event, QueryCellFormattedText, to set the formatted value in a cell, say converting kgs to lbs. Then you could use SaveCellFormattedText to convert the value back. Here is a little sample that has values stored in kgs in column 1. The grid will display it in either kgs or lbs depending upon whether there is a # in column 2. KGStoLBS_1578.zip

Michael Feinstein
Replied On August 19, 2004 11:36 PM UTC

This seem like perfect solution, except we need a way to determine format information from QueryCellFormattedText parameters alone (the example uses another column). I was thinking to inherit ColumnDescriptor (since we want to configure it anyway), is there a way to get to ColumnDescriptor class of the cell from GridCellTextEventArgs ? Is it good way to go, or can you recommend another way? For example in DataBound grids one can override PropertyDescriptor.

Administrator [Syncfusion]
Replied On August 20, 2004 04:36 AM UTC

I am not sure what you mean by column descriptor. If you mean GridBoundColumn or PropertyDescriptor, you can get those with code like: int field = this.gridDataBoundGrid1.Binder.ColIndexToField(e.Style.CellIdentity.ColIndex); GridBoundColumn gbc = this.gridDataBoundGrid1.Binder.InternalColumns[field]; PropertyDescriptor pd = gbc.PropertyDescriptor; If you have explicitly added GridBoundColumns, then you would use the grid.GridBoundColumns collection in the above code instead of the InternalColumns collection. If you mean something else, could you explain a little more about it.

Michael Feinstein
Replied On August 20, 2004 06:07 PM UTC

Sorry I was not very clear, we are going to use GroupingGrid, and there is plenty of information in ColumnDescriptor classes (that are in TableDescriptor) to allow us to dtermine in run-time on how to format text. What we need is a way to get to the information in the events (because ControlGrid has these 2 events as well) >I am not sure what you mean by column descriptor. > >If you mean GridBoundColumn or PropertyDescriptor, you can get those with code like: > >int field = this.gridDataBoundGrid1.Binder.ColIndexToField(e.Style.CellIdentity.ColIndex); >GridBoundColumn gbc = this.gridDataBoundGrid1.Binder.InternalColumns[field]; >PropertyDescriptor pd = gbc.PropertyDescriptor; > > >If you have explicitly added GridBoundColumns, then you would use the grid.GridBoundColumns collection in the above code instead of the InternalColumns collection. > >If you mean something else, could you explain a little more about it. >

Administrator [Syncfusion]
Replied On August 21, 2004 11:55 AM UTC

Here is some code that gets at the Record for the row from within the QueryCellFormattedText event on the main TableModel.
private void TableModel_QueryCellFormattedText(object sender, GridCellTextEventArgs e)
{
	Element el = this.groupingGrid1.Table.DisplayElements[e.Style.CellIdentity.RowIndex];
	RecordRow rec =  el as RecordRow ;
	if(rec != null)
	{
		Record r = rec.ParentRecord;
		DataRowView drv =  r.GetData() as DataRowView;
		if(drv != null)
		{
			Console.WriteLine("************ " + drv[0].ToString() + "  " + drv[1].ToString());
		}
	}
}

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

;