Thursday, December 22, 2011

Displaying items horizontaly in WPF ItemsControl

I am trying my hand on Microsoft Composite Application for few days. I was trying to display list of Actions available from a moudle into a Region using following markup:

  
        
            
                
                    
                
            
            
                
                    
                        
                            
                        
                    
                
            
        
    

This displays items in vertical manner (as is default with ItemsControl and its derivatives like ListBox). I added following code to make it use StackPanel:

    
        
            
        
     

But it did not produce the desired outcome. I tried the WrapPanel also but it was still same. After some more frustration I commented GroupStyle tag:

    
        
            
                
                    
                
           
        
     

Now it worked as desired by displaying Button controls in a single row.

Wednesday, June 22, 2011

Error on Adding WCF Service Reference to ASP.Net Project

I am writing a small website using EF 4 Code First. There are some legacy tables which don't have primary key. This (not having PK) would have created complications with EF, but I needed to only read data from those table. So I decided to create a WCF service to pull the data. I defined [ServiceContract], [DataContract], [OperationContract] etc. and everything was going fine till I tried add reference to my web project. In the Add Service Reference dialog VS did find service, but when I clicked on service to fetch metadata I got following error:

There was an error downloading 
'http://localhost:8732/Design_Time_Addresses/LegacyDataService/DataService/mex'.
The request failed with HTTP status 400: Bad Request.
Metadata contains a reference that cannot be resolved: 
http://localhost:8732/Design_Time_Addresses/LegacyDataService/DataService/mex.

After some head scratching and googling about the error I found out a post on MSDN forum where somebody was putting [DataMember] attribute over an indexer. I checked my [ServiceContract] and [DataContract]s.

My [ServiceContract] read as follows:

[ServiceContract]
public interface IDataService
{
    [OperationContract]
    IList<LegacyUser> GetUsers();
    ......
    ......
}

I tried to comment the IList<LegacyUser> stuff, but the error was still there. It then occurred to me that there was an Address property which returned build user's address by concatenating other fields. After this Address property was commented the error was gone.

Moral of the story is that:
  1. you should not put [DataMember] attribute on Indexers (as mentioned in MSDN post).
  2. you should not put [DataMember] attribute on properties that use other properties with the attribute to calculate return value.

Wednesday, May 25, 2011

MySQL Error 2002

I was reading an article about MySQL replication yesterday. After reading a bit I thought it will be really easy to test it. I setup a remote MySQL server available with a friend and configured it as master. After this I fired up Ubuntu Lucid Lynx VM in VirtualBox and configured it as slave (changed my.cnf file mainly).

Now when I tried to login into MySQL I got following error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
After sifting through many posts on internet forums, I occured to me to check error logs (how intelligent, thought this should have been first thing to do). I issued following command:

tail /var/log/mysql/error.log

110525 23:19:20 [ERROR] /usr/sbin/mysqld: unknown variable 'relay-logn-index=test_slave-bin.index'
110525 23:19:20 [ERROR] Aborting

So it was only an extra 'n' that gave me so much headache. After changing 'relay-logn-index' to 'relay-log-index' it worked fine.

Thursday, January 6, 2011

Making Selected Row Visible in UltraWinGrid

I was facing a problem with Infragistics UltraWinGrid object. There were about 15 rows in the grid. Due to size of form only 8 were visible at a time. The first rows was fixed, so it cannot be moved by scrolling.

To edit row a popup form is opened on double clicking the row and a button on the form. On successful saving of editing information in popup form, parent form's grid is refreshed from database.

Upon refreshing if the very first row (just below the fixed row) was selected or popup was opened by clicking on button when selected row was not visible, it is not scrolled to view.

Unfortunately windows grid does not contains a method like web grid which scrolls selected row to view (ScrollToView).

After some hit and trail I found the following solution:

myGrid.ActiveRowScrollRegion.FirstRow = row;//row is selected row (can get using myGrid.ActiveRow)