June 30, 2011

Cannot apply indexing with [] to an expression of type System.Collections.Generic.IEnumerable

Cannot apply indexing with [] to an expression of type 'System.Collections.Generic.IEnumerable<ANY_TYPE>

If used of IEnumerable SampleArray then you can access to elements like:
- SampleArray[index] WRONG
- SampleArray.ElementAt(index) RIGHT
Because the IEnumerable interface dose not support of [] for indexing :-))

June 15, 2011

Server-generated keys and server-generated values are not supported by SQL Server Compact

{"Server-generated keys and server-generated values are not supported by SQL Server Compact."}
{"An error occurred while updating the entries. See the inner exception for details."}

The current version of Entity Framework does not support identity keys using SQL Compact ;-(

1- Add the Guid.NewGuid() after new row like below here (for uniqueidentifier ID)

BindingListCollectionView CurrentView = categoriesViewSource.View as BindingListCollectionView;
Table tb1 = CurrentView.AddNew() as Table1;
tb1.ID = Guid.NewGuid();

2- Another solution can be find the last and greatest ID and make a new one with ++ to that like here (for int ID)

3- Another solution can be used of  DateTime.UtcNow.Ticks (for bigint ID)

PS: There's a little problem with True value for Identity property in SQL CE Table and must be set to False.

June 11, 2011

Make invisible layer in Flash CS5

Hide layer (with click on eye icon) for invisible in design time and then right-click on layer and checked the Guide item for invisible in run-time.

June 06, 2011

Primary side of the relationship error on Entity Framework

The relationship 'RELATIONSHIP NAME' has columns that are not part of the key of the table on the primary side of the relationship. The relationship was excluded.

Attention to the RELATIONSHIP NAME in your database. The Relationship Name must have a unique name and this error comes from a duplicate relationship name in database. Entity Framework (EF 4.0) generator have problem with duplicate relationship names from databases.

June 01, 2011

WPF SelectedValue for TreeView

- How to programmatically select an Item in a WPF TreeView
- How to programmatically selecting an Item in a WPF TreeView
- How to SelectedItem in a WPF TreeView
- How to set SelectedItem or SelectedValue in C#/WPF TreeView
- WPF TreeView SelectedItem should have set accessor …
- How to programmatically change the SelectedItem in a WPF TreeView

The Solution is simple and quick with just a little method
TreeViewItem matchItam = SelectTreeViewItem(this.treeView1.Items, "sample value");

The code is here
private TreeViewItem SelectTreeViewItem(ItemCollection Collection, String Value)
    if (Collection == null) return null;
    foreach(TreeViewItem Item in Collection)
        /// Find in current
        if (Item.Header.Equals(Value))
            Item.IsSelected = true;
            return Item;

        /// Find in Childs
        if (Item.Items != null)
            TreeViewItem childItem = this.SelectTreeViewItem(Item.Items, Value);
            if (childItem != null)
                Item.IsExpanded = true;
                return childItem;
    return null;