I knew it should have been there. But somehow it didn't pop up in search no matter how I tried to find how to emulate key press in .NET.
So, to emulate key pressing in .NET just use System.Windows.Forms.SendKeys class. As simple as that.
Here I will post problems I and my colleagues met and solutions we found.
Monday, March 24, 2008
Emulating key pressing in .NET
Tuesday, February 26, 2008
Alter column set default doesn't work in T-SQL 2005
Looking to the MSDN help http://msdn2.microsoft.com/en-us/library/ms174123(SQL.100).aspx (Same topic I have in local MSDN Library) I could not understand why following commands did not work:
alter table [Albums] alter column [Comment] set default 'default';
alter table [Albums] alter column [Comment] set not null;
I was getting error message:
Incorrect syntax near the keyword 'set'.
First I found this solution for default:
alter table [Albums] add constraint DF_Albumns_Comment default 'default' for [Comment];
constraint name is optional;
For not null similar solution:
alter table [Albums] add constraint NN_Albumns_Comment check ([Comment] is not null);
produces slightly different result. This new constraint is added over existing table definitions. The definition for column [Comment] is that it still allows nulls.
But then I noticed that online help was in fact for SQL 2008 compact edition, and later I found updated version (February 2008) for SQL 2005
http://msdn2.microsoft.com/en-us/library/ms190273.aspx
Now ther is no option for default here, so solution with new constraint should be used. But for not null constraint I can use this:
alter table [Albums] alter column [Comment] varchar(30) not null;
And no mistery.
Monday, February 18, 2008
SENS events
I decided to write very small program that would calculate how much time someone spends at computer. Not too sophisticated, just based on login-logout time and screen saver. Researching the subject I found that this days it should use System Event Notification Services (SENS) to be able to work on Windows Vista. And then I had very hard time figuring out how to make it work based on MSDN information.
What helped me is this article, particularly example.
http://dotnet.sys-con.com/read/105651_1.htm
The program is not written, but link is still good. And I tried example, it works.
Thursday, January 17, 2008
Application.ThreadException Event is static
Today I had problems with handling exceptions in new application. Instead of showing message my application just terminated, and I couldn't find where.
The reason was that Application.ThreadException Event is static event, but handler I assigned to it was not static method. I didn't get any warnings, it just didn't work.
Extracting Date from DateTime in MS SQL
I don't know may be you know better way of extracting Date from DateTime in MS SQL, but the one I like is
DATEADD(d, 0, DATEDIFF(d, 0, [DateTime Column]))
Using conversion would be converting datetime to number, then to integer, then back to date. I didn't measure performance, but don't see much problems with arithmetic.
Tuesday, December 18, 2007
Changing background for selected item in WPF ListBox
When I wanted to change background color for WPF ListBox the first thing I did was creating triggers in the style:
The problem is that it doesn't work. I have to change resources instead. Here is the link that describes it very well.
http://blogs.msdn.com/wpfsdk/archive/2007/08/31/specifying-the-selection-color-content-alignment-and-background-color-for-items-in-a-listbox.aspx
Friday, December 07, 2007
Master Detail Binding in WPF
I spent hours today trying to figure out how to display Master Detail relation in two lists, if I have good old DataSet with Relation between tables. All examples I could find in Google were about objects or XML structures.
What worked is this:
Let's assume we have DataSet with two tables, MasterTable and DetailTable. We also have DataRelation named Master_Detail. The binding in code looks like that:
masterList.IsSynchronizedWithCurrentItem = true;
detailList.IsSynchronizedWithCurrentItem = true;
DataSet dataSet = CreateDataSet1();
DataView dataView = new DataView(dataSet.Tables["MasterTable"]);
Binding binding = new Binding();
binding.Source = dataView;
masterList.SetBinding(ListView.ItemsSourceProperty, binding);
binding = new Binding();
binding.Source = dataView;
binding.Path = new PropertyPath("Master_Detail");
detailList.SetBinding(ListView.ItemsSourceProperty, binding);
Now, let's say we have another relation named "Detail_SmallDetail". We would add following:
smallDetailList.IsSynchronizedWithCurrentItem = true;
binding = new Binding();
binding.Source = dataView;
binding.Path = new PropertyPath("Master_Detail/Detail_SmallDetail");
smallDetailList.SetBinding(ListView.ItemsSourceProperty, binding);
I didn't figure out how to do it in XAML yet.
Saturday, October 20, 2007
GeometryModel3D, DrawingBrush and TextureCoordinates
I tried to use DrawingBrush for GeometryModel3D object.
First, I created very simple object (cube without one side) using simple Blue brush, and I could see it. But when I tried to use DrawingBrush, my object became invisible. Apparently, when DrawingBrush is used, TextureCoordinates property for MeshGeometry3D object have to have correct values, and cannot be empty.
Thursday, October 11, 2007
Timers
Experimenting with timers in WPF I found some interesting differences from Windows Forms.
- We cannot use timer from Windows.Forms namespace, which leaves us to Timer from System.Timers or System.Threading namespaces.
- Both these timers execute their events/delegates in separate thread, from ThreadPool, which means we cannot directly operate with controls now. Again this is opposite to Windows Forms timer.
- Timer from System.Timers object has SynchronizeObject property of ISynchronizeInvoke interface type. However, WPF controls do not support this interface so we cannot use it. Again, this is not the same as for Windows Forms.
- WPF controls do not have Invoke methods as Windows Forms controls.
- What we can and should use is Control.Dispatcher.Invoke method.
Friday, October 05, 2007
Books
Ok, I am in book reading mode.
1. WPF (Unleashed) by Adam Nathan.
Great book. The reason for this book being so good is the way it's organized. The "main course" of the book is the very well written guide to learn WPF without making it too complicated. And there are Notes and Tips that give you the direction where you should dig to know more. Highly recommend.
2. WCF (Unleashed) by Craig McMurtry.
I am struggling with this book. I am at the beginning of it and at this moment I still have determination to finish it. But it's hard. In opposite to WPF book where complex concepts explained simply, here simple concepts can be understood after reading paragraph two or three times. Disappointment, actually.
3. Expert C# 2005 Business Objects by Rockford Lhotka.
I am in chapter 2 yet, but I am in nirvana reading this book. The subject itself is very interesting to me. I am little bit obsessed with idea of "application frameworks". By this moment, I have no single point of disagreement with the book. And as WPF, the author really tries to explain his concepts and ideas in human language. Highly recommend.
Friday, September 14, 2007
Semicolon in SQL Startup parameters
It took me some time to find that when more than one parameter is used as Startup Parameters in SQL Sever, they should be separated by semicolon rather than space.
For example:
-dC:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\DATA\master.mdf;-eC:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\LOG\ERRORLOG;-lC:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\DATA\mastlog.ldf;-T4616
Tuesday, August 14, 2007
Understanding 3d in WPF
When I read about 3d support in WPF in MSDN documentation, I had difficulties with understanding. In fact, whole area of WPF in MSDN disappointed me. Anyway, this link helped me to understand it better. http://blogs.msdn.com/danlehen/archive/2005/11/06/489627.aspx
parseInt surprise
It turned out I couldn't make it with my project. However, I still see some problems where solutions are either not obvious for me from documentation, or I just couldn't find them there. And it could be not even related to .NET. I decided to put them here anyway.
Here is one of them. I developed Gmail notifier plugin for Google Desktop. This was my first and currently the only project in Javascript. One of the problem I had was with parseInt function. It turned out that the function is very smart, and trying to figure out what base should be used. And since I tried to parse month or day from the date, I had leading zeros. That made the function think the base is 8, so numbers '08' and '09' could not be parsed.
Thanks to http://www.faqts.com/knowledge_base/view.phtml/aid/8108
Sunday, September 10, 2006
I wrote a post, I presses spell-check, I disabled popup-window, I lost everything I wrote.
I cannot repeat :(
I short, I cannot stop thinking about this project, I started it again.
VS2005 option for Windows Installer sucks when it comes to updates.
http://support.microsoft.com/kb/912019/en-us - is really a problem. I wasted today's evening, but then closed all forms, closed VS2005 and opened it again, and it helped
Friday, January 27, 2006
VistaDB as deskop database for .NET application
So, I finally decided to write application. I had that idea for a long time and understood, that I will not sleep well until I do it. So, I canceled my Netflix subscribtion and ready to go!!!
I am going to have server with Web Services, and client, better to say Smart Client :) For server I am going to use MS SQL Express. But, I need light database engine for client. My first experiment will be done with VistaDB. SQL Express is to heavy, Access needs Office for provider. And, I don't know, I never liked Access. FireBird - I am going to test it too, but it looks too "geeky" for me.
In this blog I will post the history of this project. From my previous post it is clear, that it is about media library.
It would be good if this post could give me a license for VistaDB, because I am not ready to pay for it yet, since I am not sure that I will have guts to finish the project. My estimates for this project (and I will work only at nights) - 6 months.
VistaDB 2.1 database for .NET has been released
This 2.1 update includes over 60 improvements, including new support for .NET 2.0 and Visual Studio 2005 VistaDB is a small-footprint, embedded SQL database alternative to Jet/Access, MSDE and SQL Server Express 2005 that enables developers to build .NET 1.1 and .NET 2.0 applications. Features SQL-92 support, small 500KB embedded footprint, free 2-User VistaDB Server for remote TCP/IP data access, royalty free distribution for both embedded and server, Copy 'n Go! deployment, managed ADO.NET Provider, data management and data migration tools. Free trial is available for download.
- Learn more about VistaDB
- Repost this to your blog and receive a FREE copy of VistaDB 2.1!
Friday, January 20, 2006
Reading text from file
I didn't touch .NET for several months, because my current work is not connected to it. But recently I wanted to make small program for myself, reading TAG from MP3 file.
Well, I spent some time figuring out how to do it properly. My final approach at this point looks like this.
System.IO.Stream stream is parameter
byte[] buffer = new byte[30];
System.Text.Encoding enc = System.Text.Encoding.GetEncoding(0);
if (!enc.IsSingleByte)
enc = System.Text.Encoding.ASCII;
stream.Read(buffer, 0, 30);
title = enc.GetString(buffer).TrimEnd('\0');
Tuesday, July 05, 2005
KeyedCollection
Usually generic collections may be found in System.Collection.Generic namespace. But this very useful one, KeyedCollection, I found in System.Collection.ObjectModel.
Tuesday, June 21, 2005
Wednesday, March 16, 2005
Expressions, Parent, Master-details
This is not so well known problem. Probably because it is weird to do it so. Anyway, it does not work.
I had master/detail relationship between two tables. In detail table I had expressions like
Parent("groups_users").Name
Which means I tried to get value from parent record using relation "groups_users". Unfortunately, when I inserted record into parent table, and then inserted record into detail table without posting data to server, I got exception that "Original value is not available". It is true, that original value is not available for new records, it is just unclear why current value is not taken.
I could not find workaround with expressions and gave up, retrieving data manually.
ReadOnly Exception Error when Inserting with an Expression Column
This is well known problem. That means this is an issue for many people and we could not pass it.
The problem is that if DataTable has expression columns, and Insert (or Update) SQLCommand returns some values, exception will be raised that ReadOnly property cannot be changed.
There is workaround. I may try manually refresh data and updat field values. Something like this:
SqlDataReader r = employeeRecordCommand.ExecuteReader(CommandBehavior.SingleRow);
if (r.HasRows)
{
r.Read();
for (int i = 0; i < r.FieldCount; i++)
{
string s = r.GetName(i);
if (string.Compare(s, "contact_id", true) != 0)
{
if (dataRow.Table.Columns.Contains(s))
dataRow[s] = r[i];
}
}
}
r.Close();
Here is the link to description of the problem:
http://www.error-bank.com/microsoft.public.dotnet.framework.windowsforms.databinding/_35_HCSYiV0DHA.2328@TK2MSFTNGP10.phx.gbl_Thread.aspx