Archives for the ‘.Net’ Category

BindingSource and Saving data

TIP:
If you bind controls to data using BindingSource, make sure you call
bindingSource1.EndEdit()
before you serialize to your data store. It’ll save a few red-faces.
Chui

ShortcutsEnabled on TextBox (WinForms DotNet) does not perform SelectAll with Control+A

In the KeyPress event handler

If Asc(e.KeyChar) = 1 Then
CType(sender, TextBox).SelectAll()
e.Handled = True
End If

technorati tags:.net, textbox, [...]

ActiveX is the weakest link

Once in a while, it is gratifying to see how Microsoft’s embrace and extend comes back and bite them in the a***. Take Microsoft’s Internet Explorer, back when MS was defending their Windows OS turf against Netscape’s Browser OS. Microsoft, in their infinite wisdom, decided to extend the browser to include ActiveX applets. Now there is already a large base of ActiveX components on the Windows platform, so naturally, adding ActiveX components to web browsers would help entrench Microsoft’s dominance on the client side right?

As history has turned out, the answer is a resounding NO.

ASP.net GridView Shortcut

When dealing with Strongly Typed datasets on the ASP.net GridView 2.0, I found myself writing one too many lines of code like this:

<asp:TemplateField HeaderText="Category">
<ItemTemplate>
<%# DataBinder.Eval(
((System.Data.DataRowView) Container.DataItem).Row,
"CategoryRow.CategoryName") %>
</ItemTemplate>
<asp:TemplateField>

Solution?

<asp:TemplateField HeaderText="Category">
<ItemTemplate>
<%# EvalEx(Container.DataItem, "CategoryRow.CategoryName") %>
</ItemTemplate>
<asp:TemplateField>

protected object EvalEx(object DataItem, string [...]

Don’t Fight the .Net GridView

The .Net GridView prefers to work through DataSources. I tried to use old style Fill dataset, then DataBind() and it simply doesn’t play well with Editing.
In addition, the ObjectDataSource.DataObjectTypeName is riculously underpowered. This version doesn’t get types of inner classes. It uses System.Web.Compilation.BuildManager.GetType instead of System.Type.GetType.

System.Type.GetType("MyStronglyTypedDataSet.MyTableRow"); // works
System.Web.Compilation.BuildManager.GetType("MyStronglyTypedDataSet.MyTableRow", true); // fails

Update 1 : Inner [...]

Seven things you should know about ASP.Net GridView

Read this and it’ll save you tons of grief later
… Where I attempt to define best practice for using ASP.Net GridView control

Use nested SELECT statements instead of JOIN statements so that UPDATE, INSERT queries get generated automatically
SELECT
ProductID, SupplierID,
(SELECT Name
[...]