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. Image for the cookie policy date

Custom display of numbers in GridDataBoundGrid

Hi, I have a bunch of numbers that I display in a GridDataBoundGrid. I get these numbers from a query run on an ACCESS database. From the database these numbers come in the English units (foot, lbs., sec. etc.) So the DataSet object in the memory that holds the results of the query has these numbers in English units. The user wants to have the option to view these numbers (being displayed in GridDataBoundGrid) either in English units or metric units. He/she can to do so by choosing the appropriate option from a menu. These numbers are also shown in a PropertyGrid control. There we applied this unit conversion by overriding the follwoing functions of the PropertyGrid control provided by Microsoft: 1) public object GetValue(object component) 2) public void SetValue(object component, object Value) and a few others. I seek your advice on how we can accomplish the same thing in the GridDatBoundGrid control and what are the methods that we would need to override. I small working example would be great. Thanks for your help, Sachin.

8 Replies

AD Administrator Syncfusion Team May 2, 2003 07:06 PM UTC

Attached is a sample that uses the new formatting events in version 1.6. This version is currently only available as a beta release. If you do not want to edit the values in the formatted form, you can do handle this task in a PrepareViewStyleInfo event. Below is a snippet that displays inches stored in column 3 as feet in the grid display. But this code will display the values in inches when you start editing the cell. If you want the editing text to be formatted, then ther eis more work to be done.
private void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
	if(e.ColIndex == 3 && e.RowIndex > 0)
		//inches from the stored data to feet in the displayed data
		string s = e.Style.Text;
		if(s.Length > 0 )
			double d = double.Parse(s);
			d = d / 12d;
			e.Style.Text = d.ToString("####.0");

SB Sachin Bammi May 4, 2003 07:22 PM UTC

Hi Thanks for your reply. When would version 1.6 be available ? Also is there no other way of doing this unless we upgrade to version 1.6. Please advise. regards, Sachin.

AD Administrator Syncfusion Team May 4, 2003 08:47 PM UTC

I don't know exact date when the 1.6 will be released. Did the PrepareViewStyleInfo event not work for you?

SB Sachin Bammi May 5, 2003 01:47 PM UTC

Probably I did not quite understand what you were trying to say in your previous message, but I could not get the project that you sent to run. It does not recognize the "GridCellTextEventArgs" object. Which is why I was wondering about the availability of version 1.6 Also what we are really looking for is the editing text to be formatted in the databound grid cell when the user changes the unit system. Your suggestions on the same would be very helpful. Thanks for your help, Sachin.

AD Administrator Syncfusion Team May 5, 2003 03:37 PM UTC

You can use the PrepareViewStyleInfo code listed above without using 1.6. It will take values stored in inches in the 3rd column of your database, and display them in the grid in feet. The PrepareViewStyleInfo is all you have to add to get this part working. But when you click a cell to start editing it, you will not see feet, but the inches (the unformatted data). To do editing, you would be better served by getting the 1.6 code. If you will update one of your support incidents, I can send you a link for a release made available today. This is still being deemed beta code for the time being.

SB Sachin Bammi May 9, 2003 12:54 PM UTC

Hi I have upgraded to version 1.6 as you had advised. You mentioned more work was needed if I were needed to edit the numbers in the displyed format. Could you please elaborate on that. Thanks for your help. regards, Sachin.

AD Administrator Syncfusion Team May 9, 2003 01:19 PM UTC

Here is a sample that uses the new QueryFormattedCellText event (new in version 1.6) to conditionally format values. It has a column whose raw data is in feet, but you can display the column in inches, meters or centimeters. There is a checkbox that sets how the edited values are interpreted (whether they are being edited in raw units or the formatted units). The CurrentCellStartEditing and SaveFormattedCellText events are used to handle this task.

SB Sachin Bammi May 9, 2003 07:26 PM UTC

Clay, Thanks for your help. regards, Sachin.

Live Chat Icon For mobile
Up arrow icon