Skip navigation

Category Archives: c#

The answer is pretty simple. Cause they were made to be sold, no as a primary platform a human person can keep, work, use it for a long time. This is economy in fact, progress. But how would you call it “progress” when even the developer tools are bugged no matter what service packs they produces released.

Let me be straigth. I was working in the past days to GPS server platform (a new one). Project went perfectlly till about 80% when taaa-daaa blue screen. I was like WTF !!! “Windows fucked me again !”. I restart, after a long period of waiting to load i can log in. “Wonderfully !”, i said. I open Visual Studio ’08 and trying to load project so i can finish my work. Again blue screen ! I follow same shitty restart steps and again, i open VS08. I open another project. Works !!! I try to open my project, blue screen.

Went outside smoking and trying to think what options i got. Ummm…only one: reinstall OS, VS08. Bad stuff is that i got like 30GB of pictures on my main drive. The second one is also full with movies i took in my holidays. Lazy to burn them down(You should imagine that). Suddenly, an ideea. What if…(this is how all good things start, isn’t it ?) i create a new project, i copy/paste the code and after i remake the design. Would take me less time !! Did that, works now !

Now, this was just a story of what happend and how i manage it. But after, i search on Google for the error i used to get when blue screen. Simple explanation from Micro$oft: “Windows or Memory problem.” that made me be like O_O. WTF !! can’t be memory, but let me test it. I put memory on another PC, worked like a charm. No problem at all. Put it back, reinstalled Win, VS08, .NET Framework. Open project…guess…blue screen.

Uninstalled .NET Framework, open project, no error but this doesn’t help me at all. What might be ? For shure not what the Micro$oft guyz are saying.

Another finishing touch that I like to see in applications that use ListViews is the ability for the end user to re-order the columns to suit their own preferences. This blog entry discusses one approach for adding this functionality to the ListView control present within the .NET Compact Framework.
Although it is difficult to convey in a static screenshot, the screenshot above shows a user dragging the stylus over the header of the listview control to move the position of the “First Name” column.

Obtaining Draggable Columns

The System.Windows.Forms.ListView control is a wrapper over top of the native ListView control. The native ListView control supports the notion of extended styles, which allow various optional features to be enabled or disabled as desired. One of the extended styles is called LVS_EX_HEADERDRAGDROP. If this extended style is enabled the user can re-order the columns by dragging and dropping the headers shown at the top of the listview while it is in report mode.

Although the .NET Compact Framework ListView control does not expose a mechanism to enable extended styles, we can use a technique discussed in a previous blog entry of mine to add or remove the LVS_EX_HEADERDRAGDROP extended style as desired.

private const int LVM_SETEXTENDEDLISTVIEWSTYLE = 0x1000 + 54;private const int LVS_EX_HEADERDRAGDROP = 0x00000010;

public static void SetAllowDraggableColumns(this ListView lv, bool enabled){// Add or remove the LVS_EX_HEADERDRAGDROP extended// style based upon the state of the enabled parameter.Message msg = new Message();msg.HWnd = lv.Handle;msg.Msg = LVM_SETEXTENDEDLISTVIEWSTYLE;msg.WParam = (IntPtr)LVS_EX_HEADERDRAGDROP;msg.LParam = enabled ? (IntPtr)LVS_EX_HEADERDRAGDROP : IntPtr.Zero;

// Send the message to the listview controlMessageWindow.SendMessage(ref msg);}

This method allows the drag feature to be turned on and off for a given ListView control. Notice that this method makes use of a C# 3.0 feature called Extension Methods. The “this” keyword in front of the first parameter means that this method can be called as if it was part of the standard ListView control, meaning the following code snippet will work (assuming listView1 is an instance of the System.Windows.Forms.ListView control).

listView1.SetAllowDraggableColumns(true);

This is pure syntactic sugar, behind the scenes the C# compiler is simply passing in listView1 as the first parameter to the SetAllowDraggableColumns method.

Persisting Column Order Preferences

Once you have reorder-able columns it can be desirable to persist the user’s preferred layout across multiple executions of your application. It would be a pain if the columns always defaulted back to a standard order everytime the form was displayed.

The native ListView control provides two window messages, LVM_GETCOLUMNORDERARRAY and LVM_SETCOLUMNORDERARRAY that can be used to implement this feature. The code sample available for download wraps up these two window messages to allow you to query the current order of the columns by using a statement such as the following:

int[] columnOrder = listView1.GetColumnOrder();// TODO: save 'columnOrder' to the registry// or another persistent store

When columns are added to a ListView they are given an index. The first column is column 0 while the second is column 1 and so on. When columns are re-ordered they keep their index value but their position on screen changes. The array returned by the GetColumnOrder function contains the index for each column in the order that they are visible on screen. For example if the array contains the values 2, 0, and 1 it means that the last column (column 2) has been dragged from the right hand side of the listview to become the left most column.

Once we have obtained the order of the columns we can store the data in any persistent storage mechanism such as a file, a database table, or registry key. When the form is reloaded we can initialise the default order of the columns by calling the equivalent SetColumnOrder method with the value we previously saved:

// TODO: should read 'columnOrder' from the registry// or other persistent storeint[] columnOrder = new int[]{2, 0, 1};

listView1.SetColumnOrder(columnOrder);
Christopher Fairbairn

I’ve been looking these days to extend the GridView native class so i can have export to Excel. So i have tried and built another class, that will make the export. The class doesn’t relay on a specific control, but on a list of objects, every object also having a child list of objects (list meaning everything what IEnumerable means). In this way, for every property in a class a new column in XSL can be generated.

Here’s the code (alin.berce – RONUA):

using System;
using System.Data;
using System.Configuration;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public class ExportToXls
{
public static void Export(string fileName, GridView gv, string title)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader(“content-disposition”, string.Format(“attachment; filename={0}”, fileName));
HttpContext.Current.Response.ContentType = “application/ms-excel”;

using (StringWriter sw = new StringWriter())
{
HtmlTextWriter htw = new HtmlTextWriter(sw);
try
{
// render the table into the htmlwriter
RenderGrid(gv).RenderControl(htw);
// render the htmlwriter into the response
HttpContext.Current.Response.Write(“

” + title + “

“);
HttpContext.Current.Response.Write(“Generated in: ” + DateTime.Now.ToString());
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
}
finally
{
htw.Close();
}
}
}

private static Table RenderGrid(GridView grd)
{
// Create a form to contain the grid
Table table = new Table();
table.GridLines = grd.GridLines;

// add the header row to the table
if (grd.HeaderRow != null)
{
ExportToXls.PrepareControlForExport(grd.HeaderRow);
table.Rows.Add(grd.HeaderRow);
}

// add each of the data rows to the table
foreach (GridViewRow row in grd.Rows)
{
//to allign top
row.VerticalAlign = VerticalAlign.Top;

ExportToXls.PrepareControlForExport(row);
table.Rows.Add(row);
}

// add the footer row to the table
if (grd.FooterRow != null)
{
ExportToXls.PrepareControlForExport(grd.FooterRow);
table.Rows.Add(grd.FooterRow);
}
return table;
}

private static void PrepareControlForExport(Control control)
{
for (int i = 0; i

Few week ago i was playing with Google API trying to make an online tracker and offline data viewer. I mess it up lamentably. Cause of many thing, but I’m concentrate in here only over the most important ones.

1. Lack of support and integration for FAI recommended formats. As a sample, .IGC files are not supported by GE. Well, i said i can handle that. Using a 3′rd party freeware application and a script for auto processing the .IGC files, i was converting all files while i was starting the application. Task done !

2. Lack of Google Earth options available in GE API. Hell, I’ve found like maximum(probably less though) 15 functions/extends that i can use in my code. I found out in the end, it’s lost time. Everyday i worked on this project means lost time.

3. Problems integrating GE in your application. HA ! Was a mess trying this. You loose focus, need to PInvoke to hide screens, windows. Even more, it’s not only implementing (at the beginning the map only), but the controls too.

Final conclusions. They have a lot to work so make this API developer related, for all kinds of developers, for novice ones till guru’s. Thought it’s a start.

Hell, yesterday i got a new task. To implement for our company mobile software applications a IPhone gesture based user interface(UI). It’s really shitty, no matter what. In fact, the main problem is that i have to use a complex neural network algorithm combined with gesture management. Normally, it will take like 3 months to complete the this, except the 3D part using DirectX(preferably) or OpenGL.

Then the problems starts. Creating a 3D interface using DX implies a lot of things, and if we do a economic feasibility study we get nowhere. Technically it’s feasible, at the limit though.

Been founding this: .NET C# Application to Create and Recognize Mouse Gestures

Looking around over it, seems to me that it’s a point of start. I’ll try contact Daniele to talk with him about this. Till then, I’ll put an eye over the code provided.

More informations and links about this can be found on the following websites:

Artificial neural network
Project Doc-WMG
Mouse gesture recognition

PS: I have forgot, Liverpool won 4-2 against Arsenal. Great game ! Bring the Cup to the KOP !!

Follow

Get every new post delivered to your Inbox.