DataGridView, FormattingException, DataError, and PreferredSize ~ Auto-Sizing Issue

Alright so I think I now have a good handle on this now. If you are using auto sizing for your columns, you might run into a formatting exception. The error you get says that you can handle the error in the DataError event.

If you start error handling within that event you might notice that you get a context of 5 which says it is either a Formatting or PreferredSize data error context. To quote MSDN:

A data error occurred when calculating the preferred size of a cell. This value indicates that the DataGridView failed to calculate the preferred width or height of a cell when programmatically resizing a column or row. This can occur if the cell failed to format its value.

Cancel the event by issuing the following e.Cancel = True after checking to make sure that the DataGridViewDataErrorEventArgs (e) has the context of 5 for PreferredSize

Advertisement

Visual Basic 2010 Object and List Initialization

I just found this out and I am really excited about it! The With & From are cooler than ever!

Check this out:

Module Module1
Private Class TestClass
Public Property Subject As String
Public Property Grade As String
Public Property Student As String
End Class
Sub Main()
Dim myTest As New TestClass With {.Grade = "A+", .Student = "Myself", .Subject = "Advanced Chromotography"}

Dim test As New System.Collections.Generic.List(Of TestClass) From {
myTest,
New TestClass With {.Subject = "Math", .Student = "John Bowman", .Grade = "B"}}

End Sub
End Module

The With and From are now part of the declaration statement, saving even more real estate on the screen.

Powershell Retrieving Remote System Time

Compare Local Date and Time to a Remote Computer

This is a rather interesting problem. I was doing a comparison between an audit table and a trace for SQL Server, which was proving to be dificult as I soon realized there was latency as well as the system date’s had an offset. So I turned to my good old friend, Powershell. Powershell has a very nice interface for coding against WMI, which I fully leveraged in this code snippet.

#Server name here. 
$ServerName = <Server Name Here>
#Retreive the localtime of the server. 
$remoteDate = Get-WmiObject -ComputerName $ServerName -Class win32_operatingsystem -Property LocalDateTime
#Converting a WMI time to a standard datetime format. 
$remoteDate = [System.Management.ManagementDateTimeConverter]::ToDateTime($remoteDate.LocalDateTime)

$localDate = Get-Date

#Displaying the difference. 
$remoteDate - $localDate

Visual Basic Basics: Visual Basic 2010 – Implicit Line Continuation

VB Line Continuation Operator (_ underscore)

Yay _

no more _

under scores _

for line continuation!!!!!_

It was one of my pain points in VB. Please visit the below, he does a wonderful job explaining it.

Visual Basic 2010 : Implicit Line Continuation – Fryan’s Digital World.

And of course, we all know that Visual Basic is superior to C#:

http://www.simple-talk.com/dotnet/.net-framework/10-reasons-why-visual-basic-is-better-than-c/

Honestly I like both, but I am partial to VB, C# is a little more masochistic.

VB.Net C# Designtime Error ~ ‘.ctor’ is not a valid identifier.

Tired of searching you project for that string? The answer is simple, which was proposed by Vladmir from Serbia on MSDN. The name of your class or form shares it’s name with a function or subroutine contained within that class. Like below:

public class Form1

private sub Form1()

end sub

end class

Changing the name of the method will fix this issue.

OracleConnection ~ Connection String Nightmare

I spent quite a bit of time today debugging an oracleconnection object. It would fail everytime the connection string property was set. This is what I would recieve in the error log:

Faulting module name: KERNELBASE.dll, version: 6.1.7601.17651, time stamp: 0x4e2111c0

Exception code: 0xe0434f4d

Fault offset: 0x0000d36f

I didn’t get to far Duck Duck Go’ing (or Googling) on this so I threw the assignment into an try catch block. I got an error  “Connection string is not well formed”. Connectionstrings.com had a great section on Oracle so I copied/pasted it into my code changing the pertinent data. Same issue.

After trying several things I discovered that the connection strings for Oracle cannot have a trailing semi-colon.

Data Source=IDWorks;User Id=IDWorks;Password=idw;

Data Source=IDWorks;User Id=IDWorks;Password=idw

Hope this saved you some time!

DataGridViewComboBoxColumn requires multiple clicks to select an item

I am reposting this because I think this guy did a good job posting this. I wish I got to this first! 🙂

DataGridViewComboBoxColumn requires multiple clicks to select an item.