We can create DataGridTemplateColumn from code behind by defining a DataTemplate in the ResourceDictionary xaml and then use the DataTemplate to create the DataGridTemplateColumn.
In the below sample code, I am creating a data grid column with checkbox.
In the ResourceDictionary xaml, add DataTemplate for the checkbox:
<DataTemplate x:Key="CheckboxTemplate">
<CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}" />
</DataTemplate>
From the code behind create the DataGridTemplateColumn for the checkbox:
DataGridTemplateColumn checkboxColumn = new DataGridTemplateColumn()
{
CellTemplate = App.Current.Resources["CheckboxTemplate"] as DataTemplate
};
Thursday, May 5, 2011
Double click issue with DataGridCheckbox column
DataGridCheckboxColumn in DataGrid seems to have double click issue. One has to click twice to check or uncheck, first click to select the row and the second click for the checkbox. We can use DataGridTemplateColumn instead for the checkbox which does not have double click issue.
sample code:
<DataGridTemplateColumn Header="Name">
<controlsData:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Content="{Binding Name}" IsChecked="{Binding Path=IsSelected,Mode=TwoWay}" />
</DataTemplate>
</controlsData:DataGridTemplateColumn.CellTemplat>
</DataGridTemplateColumn>
Monday, February 28, 2011
IIS version on Windows versions
Every Windows version has it's own IIS version. Here are some Windows versions:
Windows XP Professional - IIS version 5.1
Windows Server 2003 - IIS version 6.0
Windows Vista - IIS version 7.0
Windows Server 2008 - IIS version 7.0
Tuesday, February 22, 2011
Using WebGet and WebInvoke
nice article on WebGet and WebInvoke attributes: Using WebGet and WebInvoke
Thursday, February 17, 2011
LINQ to Entities does not support Contains() method
We are using .NET Entity Framework in our project and today I wrote a LINQ to Entities query to fetch records from table A if corresponding records are not found in table B. Let us take example of customer orders scenario. I want to get all the customers who don't have a order in the Orders table. What I needed was "NOT IN" or "NOT EXISTS" SQL equivalent in LINQ to Entities. I knew that we have Contains() method in LINQ to SQL which is equivalent to NOT EXISTS in SQL. So, I tried following LINQ to Entities query to return all the costumers who don't have a order in the Orders table:
from c in context.Customers
where !( from o in context.Orders select o.CustomerId ).Contains( c.CustomerId )
select c
I was confident this would work, but no the above query did not work!!. I got an error that LINQ to Entities does not support Contains() method. It is frustrating to know that the same Contains() method works in LINQ to SQL but not in LINQ to Entities. Why not support such basic functionality.
I had other frustrating moments with LINQ to Entities too. I prefer to just use LINQ to SQL and stay away from LINQ to Entities.
from c in context.Customers
where !( from o in context.Orders select o.CustomerId ).Contains( c.CustomerId )
select c
I was confident this would work, but no the above query did not work!!. I got an error that LINQ to Entities does not support Contains() method. It is frustrating to know that the same Contains() method works in LINQ to SQL but not in LINQ to Entities. Why not support such basic functionality.
I had other frustrating moments with LINQ to Entities too. I prefer to just use LINQ to SQL and stay away from LINQ to Entities.
Wednesday, February 16, 2011
The NOT EXISTS equivalent in LINQ to SQL
Here is a sample LINQ to SQL query to return all the customers who don't have an order in the Orders table:
var query =
from c in Customers
where !( from o in Orders select o.CustomerId ).Contains( c.CustomerId )
select c;
var query =
from c in Customers
where !( from o in Orders select o.CustomerId ).Contains( c.CustomerId )
select c;
Tuesday, February 8, 2011
Useful Keyboard Shortcuts for Microsoft Visual Studio
Here are some useful keyboard shortcuts for Microsoft Visual Studio:
F5 => Build
CTRL+F5 => Execute
F9 => Breakpoint for debugging
F10 => Single step during debugging
F11 => Get into function or method during debugging
CTRL+K+K => Book Mark
CTRL+K+N => Go to next book mark
CTRL+K+P => Go to previous book mark
CTRL-C => Copy
CTRL-V => Paste
CTRL-X => Cut
CTRL-A => Select All
CTRL-Z => Undo
ALT-TAB => Switch between open programs
CTRL-TAB => Switch between windows in the current program
CTRL-END => Go to the end of the document
CTRL-HOME => Go to the start of the document
END => Go to the end of the line
HOME => Go to the start of the line
SHIFT-END => Select from the current cursor position to the end of the line
SHIFT-HOME => Select from the current cursor position to the start of the line
F4 => Repeat the last action (only works in most Microsoft Office
applications, such as Excel/Visio/ Word, but very powerful in those)
CTRL-SHIFT-RightArrow => Select from the current cursor position to the end of the current word (including space)
CTRL-SHIFT-LeftArrow => Select from the current cursor position to the start of the prior word
CTRL-F => Find (open the Find dialog in many applications)
CTRL-H => Find and Replace (open the Find and Replace dialog in many
applications)
CTRL-SHIFT-UpArrow => Select from the current cursor position to the start of the current line of next line up
CTRL-SHIFT-DownArrow => Select from the current cursor position to the end of the current or next line down
CTRL-G => Go to a specific line number (works in notepad, Visual Studio,
other editing programs)
F5 => Build
CTRL+F5 => Execute
F9 => Breakpoint for debugging
F10 => Single step during debugging
F11 => Get into function or method during debugging
CTRL+K+K => Book Mark
CTRL+K+N => Go to next book mark
CTRL+K+P => Go to previous book mark
CTRL-C => Copy
CTRL-V => Paste
CTRL-X => Cut
CTRL-A => Select All
CTRL-Z => Undo
ALT-TAB => Switch between open programs
CTRL-TAB => Switch between windows in the current program
CTRL-END => Go to the end of the document
CTRL-HOME => Go to the start of the document
END => Go to the end of the line
HOME => Go to the start of the line
SHIFT-END => Select from the current cursor position to the end of the line
SHIFT-HOME => Select from the current cursor position to the start of the line
F4 => Repeat the last action (only works in most Microsoft Office
applications, such as Excel/Visio/ Word, but very powerful in those)
CTRL-SHIFT-RightArrow => Select from the current cursor position to the end of the current word (including space)
CTRL-SHIFT-LeftArrow => Select from the current cursor position to the start of the prior word
CTRL-F => Find (open the Find dialog in many applications)
CTRL-H => Find and Replace (open the Find and Replace dialog in many
applications)
CTRL-SHIFT-UpArrow => Select from the current cursor position to the start of the current line of next line up
CTRL-SHIFT-DownArrow => Select from the current cursor position to the end of the current or next line down
CTRL-G => Go to a specific line number (works in notepad, Visual Studio,
other editing programs)
Subscribe to:
Posts (Atom)