Thursday, March 29, 2012
C# Converting PT0H0M0S to TimeSpan
I was working on importing Microsoft Project data into one of my projects when I encountered a problem where the MSP's TimePhasedData value is using the format PT0H0M0S to represent date values. I needed to convert the PT0H0M0S string to a double representing the total hours. I'm posting this code just in case someone is looking for something similar.
public static double StringToTimeSpan(string source)
int hours = 0; int minutes = 0; int seconds =0;
string number = string.Empty ;
for (int index = 0; index < source.Length; index++) {
char current = source[index];
if ("1234567890".Contains(current)) number += current;
else {
if (current.Equals ('H')) hours += int.Parse(number);
if (current.Equals ('M')) minutes += int.Parse(number);
if (current.Equals ('S')) seconds += int.Parse(number);
number = string.Empty ;
}
}
return new TimeSpan (hours, minutes, seconds).TotalHours;
}
Tuesday, March 20, 2012
ComponentOne FlexGrid columns with checkboxes
When working with ComponentOne's FlexGrid bounded to a boolean column, setting the Editor property of that boolean column will make it difficult to change the value of the column.
DataTable table = new DataTable();
table.Columns.Add("Selected", typeof(bool));
table.Columns.Add("Name", typeof(string));
table.Rows.Add(false, "Row 1");
flexGrid.DataSource = table;Column column = flexGrid.Cols[0];
column.Editor = new CheckBox();
In the example above, once the editor property of the column is set to an instance of a checkbox, changing the value of the selected column will take several tries.
I just skipped the setting the editor for boolean columns as a result and let C1FlexGrid manage it. If anyone knows of an explanation or a better way to set an editor of a C1FlexGrid column, just send me a message.
DataTable table = new DataTable();
table.Columns.Add("Selected", typeof(bool));
table.Columns.Add("Name", typeof(string));
table.Rows.Add(false, "Row 1");
flexGrid.DataSource = table;Column column = flexGrid.Cols[0];
column.Editor = new CheckBox();
In the example above, once the editor property of the column is set to an instance of a checkbox, changing the value of the selected column will take several tries.
I just skipped the setting the editor for boolean columns as a result and let C1FlexGrid manage it. If anyone knows of an explanation or a better way to set an editor of a C1FlexGrid column, just send me a message.
Subscribe to:
Posts (Atom)