Montag, 20. November 2006

The DatagridView readonly performance Control

In my current project, a winform application which searches addresses around different databases, i use the datagridview control
to display the found addresses.

I don't know how much results i get because that depends on the search criteria the user enters.

Already at results with a count of 1000 entries the performance of the grid is bad.
For example, if i sort the datasource with the click on one of the columns it needs 20-30 seconds.
Thats not really acceptable.

So i searched a little bit around and found cool results in dependency to the "virtual mode" property.

If you bind data to the datagrid with virtual mode set to true the datagrid asks for the data that should be displayed,
and ONLY that data.
Behind the scenes i have a datatable which holds my search results.
The "ask for data" is an event called "CellValueNeeded" and gives me an cell- and a rowindex.
Easy with the datatable.
Sorting is even more easy: call the datatable.DefaultView.Sort property and you're done.

CODE START

//binding the data
//this causes the datagridview to raise the CellValueNeeded Event
dataGridView1.VirtualMode = true;
dataGridView1.RowCount = currentDataView.Table.Rows.Count;

//CellValueNeeded Event
DataRow needeRow = currentDataView[e.RowIndex].Row;
if (needeRow != null && needeRow[e.ColumnIndex] != null)
e.Value = needeRow[e.ColumnIndex];
else
e.Value = System.DBNull.Value;

//Sorting
currentDataView.Sort = string.Format("[{0}] {1}", currentSortColumn, sortOrder);

CODE END

And the performance is amazing: click and get immediately results. very cool...

Summary: If you have more or an unknown amount of data to display, use the virtual mode.
You have to sort manually, set the sortglyph to the column you are sorting and give the datagridview the data it needs.
in my case i have a readonly datagrid, for editmodes enabled you have to do a little bit more :)

Some links to articles about it:

Presenting Data with the DataGridView Control in .NET 2.0
http://www.awprofessional.com/articles/article.asp?p=446453&seqNum=1&rl=1

Virtual Mode in the Windows Forms DataGridView Control
http://msdn2.microsoft.com/en-us/library/ms171622(VS.80).aspx

How to: Implement Virtual Mode in the Windows Forms DataGridView Control
http://msdn2.microsoft.com/en-us/library/2b177d6d.aspx

happy displaying ...

tingle

Montag, 10. Juli 2006

Vista Development Guidance

If you want to develop for Vista you have to check out the following Site:

http://projectglidepath.net/glidepath/overview.aspx

A Guidance Project created by Microsoft, supported by the Community.

Cool Stuff for FREE !!!

Samstag, 1. Juli 2006

Office Live Beta Launched - very cool stuff

The Office Live Website is up and running:

http://officelive.microsoft.com/

Very cool Stuff, and the best: its totally FREE !!!

You have only to pay some fee if you want to use advanced features, like Employee Management.

You get a domain for your new site, of course free and you can customize the site online. New Sharepoint is used behind the scenes.

So be sure to check it out

Mittwoch, 12. April 2006

Use Windows Explorer to copy Debug Symblos to the GAC

For those of you debugging GACed assemblies like me, you know its a little bit painfull to copy the debug symbols to it.

You should write a batch file for that purpose, but you have to go to the command prompt and type in the directory names and the mark and copy it.

To save a few key strokes, use the good old subst dos command.

  1. first type subst g: c:\windows\assembly
  2. the use the windows explorer and navigate to the g: drive
  3. and volia, you can click through the gac

Dienstag, 11. April 2006

Funny Messages

Very funny Messages, some from very known apps.

Check out the Pop-Up Potpourri @thedailywtf.com:

First one

Second One

Third one

Fourth One

Fifth one

Binary Serialization Code Snippet

In addtition to the wonderful new Code Snippet Functionality in Visual Studio 2005, i provide a binary serialization code snippet for C#. This is only to save to a binary File.

The Code Snippets from Microsoft, available here, have only the Xml Serialization.

Just put it in your #PROGRAMFILES#\Microsoft Visual Studio 8\VC#\Snippets\1033\Visual C# Directory.

Have phun,

tingle

<?xml version="1.0" encoding="UTF-8"?>
<CodeSnippets xmlns="
http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Write Class Data to a Binary File</Title>
<Author>Joerg Brunke</Author>
<Description>Writes the data from a class to a Binary file using the BinaryFormatter class.</Description>
<Shortcut>binWriteClass</Shortcut>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>filename</ID>
<ToolTip>Replace with name of the file to write the data to.</ToolTip>
<Default>Data.bin</Default>
</Literal>
<Literal>
<ID>dataInstance</ID>
<ToolTip>Replace with the instance of the class containing the data.</ToolTip>
<Default>dataToWrite</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[using(System.IO.FileStream fs = new System.IO.FileStream(@"$filename$", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write))
{
try
{
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
bf.Serialize(fs, $dataInstance$);
}
catch(System.Exception ex)
{
}
}$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>