kadara
2014-03-10T16:54:49Z
Hi,

My iGrid is filled from an Oracle database (with an SQL command).
My table has 8 columns. The last three columns are filled with numbers representing time in seconds (Begin Time, End Time, Duration; for example Begin Time = 61261, End Time = 61301, Duration = 40).
Is there a possibility to change the style of these columns to show the time in HH:MM:SS format?
Thanks.
kadara
2014-03-10T19:07:26Z
Also, I implemented the IGGroupRowSumManager function (from the example with the same name from the web page) in this project to calculate the sum of the last column (Duration). I would like to show the sum in the format of HH:MM:SS. Is this possible?
Thanks
kadara attached the following image(s):
Igor/10Tec
2014-03-11T09:22:03Z
I think the simplest way to do that is to write a custom routine that converts duration integers into the corresponding string representation and then use it to enhance the grid.

1) This routine will be used in the CellDynamicContents event to get the string representation of the cell values in the last column.

2) This routine will be used in the code that generates the custom contents of the group rows.

Different approaches of writing such a routine can be found, for instance, here:

http://stackoverflow.com...seconds-to-hhmmss-format 
kadara
2014-03-12T14:12:52Z
Thanks or your reply.

I wrote the following code to show the time format in HH:MM:SS for the last column:

Private Sub Grid_CellDynamicContents(ByVal sender As Object, ByVal e As iGCellDynamicContentsEventArgs)
		
	Dim iSpan As TimeSpan = TimeSpan.FromSeconds(iGrid1.Cells(e.RowIndex,7).Value)
		
	If e.ColIndex = 7 Then
		e.Text = iSpan.Hours.ToString.PadLeft(2, "0"c) & ":" & iSpan.Minutes.ToString.PadLeft(2, "0"c) & ":" & iSpan.Seconds.ToString.PadLeft(2, "0"c)
	End If
		
End Sub


This code is working great until I group the table. When I drag a column in the GroupBox, the following error message is appear: "Conversion from type 'DBNull' to type 'Double' is not valid"

Could you help me please? How could I handle this conversion problem?
Thanks
kadara
2014-03-12T17:00:52Z
I rewrote a little bit the previous code:

Private Sub Grid_CellDynamicContents(ByVal sender As Object, ByVal e As iGCellDynamicContentsEventArgs)
		
	If e.ColIndex = 7 Then
		Dim iSpan As TimeSpan = TimeSpan.FromSeconds(e.Text)
		e.Text = iSpan.Hours.ToString.PadLeft(2, "0"c) & ":" & iSpan.Minutes.ToString.PadLeft(2, "0"c) & ":" & iSpan.Seconds.ToString.PadLeft(2, "0"c)
	End If
		
End Sub

This code is a good one.
Thanks.
kadara
2014-04-04T05:28:44Z
Could you help me again please?
I would like to integrate the iGSubtotalManager function (from the example with the same name downloaded from the web page). Also I would like to combine the iGSubtotalManager function with the Grid_CellDynamicContents method described in the previous reply. Without using the Grid_CellDynamicContents method the iGSubtotalManager function is working well. But when I activate the Grid_CellDynamicContents method, the following error message is appear: "Conversion from string "" to type 'Double' is not valid".

The Grid_CellDynamicContents method is working well with the IGGroupRowSumManager function (from the example with the same name downloaded from the web page).

Thanks.
Igor/10Tec
2014-04-04T06:57:56Z
Can you prepare and send us a sample we can use to reproduce that problem? Then we could fix it for your personal case.
kadara
2014-04-04T08:43:02Z
OK. I will try to reproduce the code for the main form. This form read an Oracle database and put the result on the grid.



I imported the iGSubtotalManager from the sample downloaded from the webpage without any changes.

Atached you have a screenshot of the form.
Thanks.
kadara attached the following image(s):
kadara
2014-04-04T08:49:08Z
The columns 3, 4, 5 shows time in seconds. I would like to display in HH:MM:SS format and display a subtotal for the column 5.

The format of these three columns are Double.
Igor/10Tec
2014-04-04T13:51:59Z
Can you change our iGSubtotalManager sample so it works like your form and allows us to reproduce the problem? We need something we can launch on our pc to work on the problem.
kadara
2014-04-05T08:59:10Z
I created a little project to simulate the form with dates like in the project on that I work. Attached you have the project files.
Thanks
File Attachment(s):
Downtime01.zip (388kb) downloaded 66 time(s).
Igor/10Tec
2014-04-07T14:06:22Z
Ok, now it's easy to see the problem and tell you how to fix it.

First, the problem occurs because the existing Grid_CellDynamicContents event handler tries to convert a string value like "Total: 100000" to the corresponding TimeSpan value in this statement:

Dim iSpan As TimeSpan = TimeSpan.FromSeconds(e.Text)

Sure, it fails. To avoid this problem, you could exclude subtotal rows from this conversion. All subtotal rows have the Tag property set to "Subtotal", so the following code fixes the problem:

If fGrid.Rows(e.RowIndex).Tag <> "Subtotal" Then

   Dim iSpan As TimeSpan = TimeSpan.FromSeconds(e.Text)
   e.Text = iSpan.Hours.ToString.PadLeft(2, "0"c) & ":" & iSpan.Minutes.ToString.PadLeft(2, "0"c) & ":" & iSpan.Seconds.ToString.PadLeft(2, "0"c)

End If

However, I guess, it would be better not to add the "Total:" prefix to the calculated subtotal values so your subtotal values in seconds could be also formatted like the normal values.

To do this, change the line #372 in iGSubtotalManager.vb from

mySubTotalRow.Cells(myColIndices(mySubtotalIndex)).Value = "Total: " & subtotalValues(mySubtotalIndex, oldLevel)

to

mySubTotalRow.Cells(myColIndices(mySubtotalIndex)).Value = subtotalValues(mySubtotalIndex, oldLevel)
kadara
2014-04-07T17:58:19Z
Thanks for your reply.
I've implemented your suggestions in my project and it is working fine.
But now I have another little (?) problem. When the grid is filled with data for the first time (interogate the database for the first time), everything is OK. But when I execute the interogation second time (to refill the grid with the new data from the database), I received the following error: "Specified argument was out of range of valid values". But if I don't use the iGSubtotalManager, the iGrid is filled everytime when I interogated the database (without getting the error message described above).
kadara
2014-04-07T19:34:03Z
Here you have a demo project to show how the problem is appearing.
I get the error message "Specified argument was out of range of valid values" only when the grid columns are grouped. When the grid is filled without grouping the columns and with the iGSubtotalManager activated, the error message never appear.
File Attachment(s):
Downtime.zip (396kb) downloaded 69 time(s).
kadara
2014-04-09T14:02:06Z
So, I would like to ask you, if there is a posibility to clear somehow the GroupBox of the iGrid before reloading the dataset?
The re-loading of the dataset in the iGrid with the SubTotalManager activated without any kind of grouping is working well (the error message appear when the grid is grouped). Could we change the loading procedure of the dataset to do the following (with the SubTotalManager activated):
- fill the grid with the dataset without any kind of grouping;
- after filling the grid do some manual grouping;
- later clear the GroupBox automatically and reload the dataset without any kind of grouping
Igor/10Tec
2014-04-09T15:20:27Z
My answer to both latest post #14 & #15 is the following.

After working on the problem in the debugger, I detected that the problem from post #14 occurs because of the internal infrastructure of iGSubtotalManager. In a nutshell, it adds an event handler to the grid's AfterContentsGrouped event to do its work. But this event is also generated when you call the FillWithData method and the grid is cleared/repopulated, and iGSubtotalManager tries to group the grid by the specified 6th column which does exist at that time.

And yes, your thoughts of how to solve the problem go in the right direction. But a better way to solve your problem is just to deattach the Subotal Manager from the grid when you call FillWithData (and make the performance better too) using the iGSubtotalManager.HideSubtotals call, and then reattach the Subtotal Manager again after the grid was repopulated:

iGSubtotalManager.HideSubtotals(fGrid)

Dim MyOdbc As New clsOdbc

MyOdbc.GetDowntimeHydra()
fGrid.FillWithData(MyOdbc.MyDataSet.Tables("tblDowntime"))

fGrid.GroupObject.Add(0)
fGrid.Group()

iGSubtotalManager.ShowSubtotalsInCells = True
iGSubtotalManager.ShowSubtotals(fGrid, New Integer() {5})
kadara
2014-04-11T16:41:18Z
I discovered another "bug".
The iGSubTotalManager displays correct the total even if I change the cell contents from seconds to HH:MM:SS with the CellDynamicContents event handler. I tried to do this with the last column.
BUT...: if I add more than one column (in this case the last 3 columns) in the CellDynamicContents to display the content of the cell in HH:MM:SS, I get the error message 'Conversion from string "" to Double is not valid'.
In the current state of the project the declared columns in the CellDynamicContents and the SubTotalManager must be the same and only.
File Attachment(s):
Downtime01.zip (397kb) downloaded 69 time(s).
Igor/10Tec
2014-04-14T14:28:43Z
See, you convert seconds into HH:MM:SS dynamically in the columns 3-5:

Private Sub Grid_CellDynamicContents(ByVal sender As Object, ByVal e As iGCellDynamicContentsEventArgs)

	Select Case e.ColIndex
	Case 3, 4, 5
		If fGrid.Rows(e.RowIndex).Tag IsNot ("Subtotal:") Then
			Dim iSpan As TimeSpan = TimeSpan.FromSeconds(e.Text)
			e.Text = iSpan.Hours.ToString.PadLeft(2, "0"c) & ":" & iSpan.Minutes.ToString.PadLeft(2, "0"c) & ":" & iSpan.Seconds.ToString.PadLeft(2, "0"c)
		End If
	End Select

End Sub

, but you define totals only for the column with the index 5:

iGSubtotalManager.ShowSubtotals(fGrid, New Integer() {5})

In this case the the cells in the columns 3 and 4 in the subtotal rows return empty string, and you get the bug you reported.

To fix it, just define subtotals for the columns 3-5:

iGSubtotalManager.ShowSubtotals(fGrid, New Integer() {3, 4, 5})

***

But there is another problem in the CellDynamicContents event handler we're working on. To distinguish subtotal rows from normal ones, you should check whether their tag is "Subtotal" but not "Subtotal:" with colon at the end:

If fGrid.Rows(e.RowIndex).Tag IsNot ("Subtotal") Then

It's not a good idea to duplicate string constants everywhere in code, and to avoid this you can even use a special method of iGSubtotalManager to check whether a row is a subtotal row :

If Not iGSubtotalManager.IsSubtotal(fGrid.Rows(e.RowIndex)) Then

***

All is good now, but in fact you do not need this check whether a row is a subtotal one or not if you wish to format total values as HH:MM:SS too. So your event handler should be so simple like this:

Private Sub Grid_CellDynamicContents(ByVal sender As Object, ByVal e As iGCellDynamicContentsEventArgs)

	Select Case e.ColIndex
	Case 3, 4, 5
		Dim iSpan As TimeSpan = TimeSpan.FromSeconds(e.Text)
		e.Text = iSpan.Hours.ToString.PadLeft(2, "0"c) & ":" & iSpan.Minutes.ToString.PadLeft(2, "0"c) & ":" & iSpan.Seconds.ToString.PadLeft(2, "0"c)
	End Select

End Sub
kadara
2014-04-14T21:02:50Z
Thanks for your suggestions.

I do not want to display the subtotals for the 3-5 columns, only for the last column (column 5).
I would like to do the following things:
- display the columns 3, 4 and 5 in HH:MM:SS format (using the iGCellDynamicContents event handler)
- display the total for the colummn 5 (using the SubTotalManager)
kadara
2014-04-14T22:13:47Z
So, I tried the demo project with the GroupRowSumManager, and I get the same error described in the #14 post.
Atached zou have the demo project with the SubTotalManager deactivated and using the GroupRowSumManager.
File Attachment(s):
Downtime01.zip (403kb) downloaded 63 time(s).