September 2007 Entries
South Florida Code Camp
I went to the south florida Code Camp and did a session on Windows Forms Datagridview. I talked about the new features in VS.Net 2005 and customizing the datagridview. You can find the powerpoint presentation and the code on my vb-tips website. If you have any questions please feel free to email me.
I have been real busy lately and not have gotten a chance to blog in a while. I have gotten involved with project to create a webhost company KJM Solutions. We will be offering SQL Server 2005 and Asp.net 2.0 hosting hope to be...
Silverlight XAML 404 errors
I created a simple web application which uses silverlight. Once I was happy with the way it was working I deployed to my webhost. When the web page loaded the silverlight control is not displaying anything.
Fidder 2 lets you examine what is going on when a webpage is loading. I see that there is a 404 error when loading the xaml file being displayed in the silverlight control. When I log into my webhost's control panel I see the xaml file is there.
According to Tim Heuser's blog all you have to do is Mime type...
Russ Fustino's Tool Shed Tour
Use the AjaxSlideShowExtender to show pictures in a directory
The AjaxSlideShowExtender will automatically display a slide show in an image control. The slide show extender calls a shared function to get a list of slides. This tip shows hows to create slide of all the images in a folder.
The Pages HTML
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<div style="text-align: center">
<asp:Image ID="Image1" runat="server" Height="300" Style="border: 1px solid black;
width: auto" ImageUrl="images/ajax.jpg"
AlternateText="Ajax" />
<asp:Label runat="Server" ID="imageLabel1" /><br...
Sql Endpoint and DataGridViewSQL Server 2005 allows you to create webservices for accessing the data in a database. These webservices are call SQL End Points. Lets start by creating a stored procedure to get the contact name and there titles for all the customers in the northwind database.
Create PROCEDURE [dbo].[GetContacts]
AS
BEGIN
SET NOCOUNT ON;
SELECT [ContactName],[ContactTitle] FROM Customers ORDER BY [ContactName];
END
Now we can create the end point. Note for this example I am using port 88 for the end point to prevent errors if you have IIS installed.
CREATE ENDPOINT NW_Contacts
STATE = Started
AS HTTP
(
PATH = '/Contacts',
AUTHENTICATION = (INTEGRATED),
PORTS = (CLEAR),
CLEAR_PORT = 88,
SITE = '*'
)
FOR SOAP
(
WEBMETHOD 'GetContacts'
(NAME...
Vista Task Dialog
Windows Vista has some cool looking new Dialog's. This example will show how to use the TaskDialog an improved message box with Visual Studio 2005.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim x As Integer
TaskDialogHelper.TaskDialog(Me.Handle, IntPtr.Zero, "Title", "Are you sure?", "This is a test", TaskDialogHelper.TaskDialogButtons.Ok, TaskDialogHelper.TaskDialogIcon.Question, x)
End Sub
End Class
Public Class TaskDialogHelper
Public Enum TaskDialogButtons
Ok = &H1
Cancel = &H8
Yes = &H2
No = &H4
Retry = &H10
Close = &H20
End Enum
Public Enum TaskDialogIcon
Information = UInt16.MaxValue - 2
Warning =...
Getting the Back Button to work with Ajax
Microsoft's Asp.Net Ajax makes it easy to create a web page that can refresh itself with out posting back. Unfortunately when a web page updates itself using ajax the user is unable to press the back button to get back to what is was on the page before. In this article I will first show to create an ajax enable website which uses a webservice to update itself. Then we will make the back button work properly.
First create a new AjaxEnabledWebsite and lets start off by adding a webservice to the Project named Customers. This...
Microsoft Visual Basic 2005 Power Packs
Visual Basic 2005 Power Packs are free Add-Ins, Controls, Components, Tools or Samples for you to use with Visual Basic 2005 to make developing great applications even easier!
Microsoft Interop Forms Toolkit 1.0
This toolkit is aimed at simplifying the use of Visual Basic.NET WinForms within a Visual Basic 6 application. The toolkit is targeted specifically at providing tools and guidance for performing a phased migration of a VB6 forms-based application to VB.NET. The goal of a phased migration is a production release at the end of each phase that has both VB6 and .NET...
Active Directory users
There is no way to get a users password from an active directory. One of the DirectoryEntry constructor overloads allows you to specify the username and password. To see if the user name and password are correct try and create a directoryEntry object with the given username and password. If the password username combination are incorrect you will get an exception. Here is a sample function to authenicate a user.
Public Function Authenicate(ByVal username As String, ByVal password As String) As Boolean
Dim isValid As Boolean = False
Try
Dim de As New DirectoryServices.DirectoryEntry("LDAP://YourActiveDirectoryName", username, password, _
DirectoryServices.AuthenticationTypes.Secure...
Orlando Code Camp
I signed up to do two sessions at the Orlando Code Camp on March 25, 2006. I am doing a session on Windows Forms Datagridview, and another on the LINQ project. The LINQ project is a preview of a technology to be introduced in the next version of Visual Studio.
Vista: Get WinSat Info
Windows Vista has a performance index for your hardware. The scores range from 1(worst) to 5.9(best). If your application uses a lot of graphics you might get poor performance on a computer with a graphics score of 1. You can use this number to scale back on the graphics to improve your apps performance. This example gets displays the scores in the forms paint event. For this example add a reference to the WinSat 1.0 type library in the com tab.
Imports WINSATLib
Imports System.Text
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
...
Binding to a WPF Listbox Part 2
In this example we will group the data in the WPF Listbox with CollectionView class. We will add a GroupStyle which will allow us to expand or hide the grouped data. We will start off by making a List which contains an Animals class. Then we create a ListCollectionView from the list. Finally we create an CollectionView from the ListCollectionView and add a GroupDescription to it. Then we bind the ListBox to the CollectionView
Pages XAML
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<DataTemplate x:Key ="lstItem" >
<StackPanel>
<TextBlock Text="{Binding Path=Animal}"/>
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid>
<ListBox Margin="14,15,47,34" Name="ListBox1" ItemTemplate="{StaticResource lstItem}" >
<ListBox.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Margin" Value="0,0,0,5"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type...
Using XLinq to get a list of Photos from Spaces.Live.com
Storing photo albums on line is becoming very popular. Spaces.Live.com photo is one place to store albums which exposes its photo albums via an rss feed. I thought it would be nice to test out Visual Studio 2008 XLinq by getting a list of Photo's from the Tampa Code Camp and display them in WPF Listbox.
The photos I am looking for can be found here.
http://thedevfish.spaces.live.com/photos/cns!75364D9E73295107!133/feed.rss
The xml in the rss feed exposes each photo like this
<item>
<title>volunteers arrived at 630am - nikita polyakov [mvp] led them</title>
<link>http://thedevfish.spaces.live.com/photos/cns!75364D9E73295107!133/cns!75364D9E73295107!134</link>
<description><p><a href="http://thedevfish.spaces.live.com/photos/cns!75364D9E73295107!133/cns!75364D9E73295107!134" mce_href="http://thedevfish.spaces.live.com/photos/cns!75364D9E73295107!133/cns!75364D9E73295107!134"><img src="http://storage.live.com/items/75364D9E73295107!134:thumbnail"...
GotDotNet Phase out
Since the GotDotNet website is being phased out I am placing my user samples here .
Video Capture Box
A inherted picturebox control which allows you to capture an image from a webcam. Also adds a ByteImage Property to make it easier to bind to an image from a database.
Enum Windows
A module you can add to your projects which contains an enum with all the WM_ messages. Good to use when overriding wndproc.
Create a VS 2005 Debugging Visualizer
Visual Studio 2005 visualizers allow you to see the data contained in a variable. For this example we will create a visualizer to see the value of a guid. To create a visualizer we need to start with a class library project. Add a reference to Microsoft.VisualStudio.DebuggerVisualizers and System.Windows.Forms. Set the build output path in the compile tab of my project to My Documents\Visual Studio 2005\Visualizers.
.
Imports Microsoft.VisualStudio.DebuggerVisualizers
Imports System.Windows.Forms
<Assembly: DebuggerVisualizer(GetType(GuidVisualizer), target:=GetType(Guid), description:="Guid visualizer")>
Public Class GuidVisualizer
Inherits DialogDebuggerVisualizer
Protected Overrides Sub Show(ByVal windowService As Microsoft.VisualStudio.DebuggerVisualizers.IDialogVisualizerService, ByVal objectProvider As Microsoft.VisualStudio.DebuggerVisualizers.IVisualizerObjectProvider)
Dim g As Guid...
July Space Coast .Net Meeting
When: July 18 @ 6:30 PM
Where: Space Coast Credit Union Corp headquarters
Connecting Applications with WCF
Most applications of any scale need to make remote calls. Whether you need to call across processes from your smart client to a web service, from your web server to your application server, or from one client to another in a peer to peer fashion, WCF supports any kind of remote messaging or communications scenario. It doesn’t just stop at remote calls either, but also supports multiple forms of security, distributed transactions, queuing, concurrency, callbacks and many other things that are needed...
VB 2008 Extension Methods
Visual Basic 2008 adds a new features called extension methods. These allow you to add a method, or function to a type. For this example we will add an IsGuid function to strings. All extension methods must be placed in a module. The function or method must be marked as an extension and the first argument is the type the method extends.
Imports System.Runtime.CompilerServices
Imports System.Text.RegularExpressions
Module Module1
Sub Main()
Dim g As String = "82ee4145-632c-42a1-83b9-57ec163eaa17"
Dim g1 As String = "82ee4145-632c-42a1-83b9-57ec163ea17"
Console.WriteLine(g & IIf(g.IsGuid, " is ", " is not ") & "a valid guid")
Console.WriteLine(g1 & IIf(g1.IsGuid, "...
Live From Redmond Webcast Series
The Visual Basic team has put together a "Live from Redmond" webcast series aimed at the next version of Visual Basic and Visual Studio code named "Orcas". The live series starts April 18th and will continue to the end of May. Come join the Visual Basic team for this exciting series.
Here's the schedule (check the VB Developer Center for updates):
Live From Redmond: VB9 - Orcas Overview April 18th, Presented by John Stallo
Live From Redmond: VB9 - LINQ Overview April 25th, Presented by Kit George
Live From Redmond: VB9 - LINQ to SQL & O/R Designer Deep Dive May 2nd, Presented by Young Joo
Live...
WPF Bind to a Method
In this part we will bind to a method. As we type a number into a textbox the results will be displayed in label below it. For this example we use a class which figures out the area of a circle.
Let's start off with a class which calculates the area of a circle. This class has one function named CalculateArea.
Public Class Area
Public Function CalculateArea(ByVal Radius As Double) As Double
Return Math.PI * Radius ^ 2
End Function
End Class
Now that we have a class set up to calculate the area we need 2 additonal classes. The first needs...
WPF OneWay Binding Part 3
In this part we will bind to a class. We will start off by creating a grid to display the properties of the class. Finally we will show how to get the form to update itself when a value changes in the class.
Lets start off creating a class that shows some info about the computer. Here is the class.
Public Class ComputerInfo
Public ReadOnly Property UserName() As String
Get
Return Environment.UserName
End Get
End Property
Public ReadOnly Property ComputerName() As String
Get
Return Environment.MachineName
End Get
End Property
Public ReadOnly Property UpTime() As Integer
Get
Return Environment.TickCount
End Get
End Property
End Class
Ok lets register the class with the form.
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFOneWayBindToVariable"
Title="WPFOneWayBindToVariable" Height="300" Width="300"
>
<Window.Resources>
<local:ComputerInfo...
WPF OneWay Binding Part 2
In the last part we bound a label to the value of the scrollbar. In this part we will format the scrollbar's value before we display it.
To be able to format the output of a bound value you need a class which inherits from IValueConverter. For this example I am using the NumbersToWords function found here to convert the number to a word for display.
Public Class NumberToWord
Implements IValueConverter
Private Function NumbersToWords(ByVal num As Decimal) As String
Dim power_value(5) As Decimal
Dim power_name(5) As String
Dim digits As Integer
Dim result As String
Dim i As Integer
' Initialize the power names and...
WPF OneWay Binding Part 1
Windows Presentation Foundation (WPF) foundation is for building applications and experiences in Windows Vista that blend the application UI, documents, and media content. In this series of blog entries we willl start to explore some of the improvements to data binding in WPF. You will need to have the .Net Framework 3.0, Windows Vista SDK, and Visual Studio 2005 extensions for WPF and WCF installed for this sample.
For this example we will start off with a Windows Application (WPF). In the forms XMAL we will add a stack panel to hold a label and scrollbar....
AjaxToolKit Slide Show Control
While working on the Orlando Code Camp website I decided to add a page which shows a slide show of the pictures taken at code camp. The new Ajax Tool Kit Slide Show Control was perfect for this task. The photos were uploaded to the Flickr website.
The Slide Show control requires a shared (static c#) function which would return an Array of Slides. The slide class contains a link to the photo, the photos name, and description of the photo. Since I did not want to store a list of photos in a database or xml file...
ScottGu at Space Coast .Net
Recently we had Scott Guthrie who works for Microsoft stop by and present at our meeting while he was in town for DevConnections . Scott runs the teams that build the .NET Common anguage Runtime (CLR), .NET Compact Framework, ASP.NET /Atlas, Windows Forms, Windows Presentation Foundation (aka "Avalon") , IIS 7.0, Commerce Server, Visual Web Developer, and Visual Studio Tools for Avalon (aka "Cider").
Scott did a really awsome 2 hour presentation. He started off showing the new CSS features of Visual Studio Orcas. Then he moved on to LINQ and showed some really useful examples....
Vista Updates and Tools
First the Visual Studio 2005 SP1 update for Vista has been released.
Service Pack 2 for SQL Server 2005 is out. This is the only version of SQL Server 2005 that is supported on Vista.
Finally the free Virtual PC 2007 is available
Windows WorkFlow Loop
Lets create a simple Windows Workflow that uses a loop to run some code 10 times. So first create a Visual Basic Squential Workflow Console Application. In the designer layout the workflow to look like this.
Double click on the codeActivity and add the following code
Public class Workflow1
Inherits SequentialWorkflowActivity
Public intLoop As Integer = 0
Private Sub codeActivity1_ExecuteCode(ByVal sender As System.Object, ByVal e As System.EventArgs)
intLoop += 1
Console.WriteLine("Loop has run " & intLoop.ToString & " times")
End Sub
End Class
When you open the Rule Condition Editor it is interesting to note the conditon...
SMO: Connect to Remote Server
Here is a simple example on connecting to a Remote SQL Server with the SMO class. In this example I use a secure string for the password.
Dim srv1 As New Server("ServerName")
srv1.ConnectionContext.LoginSecure = False
srv1.ConnectionContext.SecurePassword = GetSecureString("Password")
srv1.ConnectionContext.Login = "UserName"
Function GetSecureString(ByVal str As String) As Security.SecureString
Dim ss As New System.Security.SecureString
For Each c As Char In str.ToCharArray
ss.AppendChar(c)
Next
' prevent changes
ss.MakeReadOnly()
Return ss
End Function
TableAdapter: Use a transaction with an TableAdapter
The easiest way to use an transaction with a TableAdapter is to use an TransactionScope. First create a TransActionScope, update the database and finally commit the transaction. Note not all database type work with System.Transactions. Add a reference to System.Transaction for this example.
Using tc As New TransactionScope
Try
EmployeeTableAdapter.Update(PubsDataSet.employee)
'complete the transaction if there were no errors
tc.Complete()
Catch
'something went wrong let the transaction roll back
End Try
End Using
Get XML string into a DataGridView
In the msdn forums I see people asking how do they get a string that contains xml to display in the DataGridView. They way to do this is to read the string into a StringReader and use the DataSet,Readxml method to convert the xml into a datatable. Note the xml must be well formed for this to work.
Dim srXML As New IO.StringReader(strXML)
Dim dsXML As New DataSet
dsXML.ReadXml(srXML)
DataGridView1.DataSource = dsXML.Tables(0)
Nested GridViews
In this example we are going to display the orders and its details from the Northwind database in one GridView. In an TemplateField place a GridView which calls a function to get the child records.
The Web Page
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" CellPadding="4" GridLines="None"
AutoGenerateColumns="False" ForeColor="#333333">
<FooterStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="True" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="OrderId" HeaderText="Order ID" />
...
List Vista RSS feeds
To list the RSS feeds added to IE7 in windows Vista add a reference to Microsoft.Feeds 1.0. You will find it in the com tab.
Imports Microsoft.Feeds.Interop
Public Class Form1
Dim mgr As New FeedsManager
Dim fldr As IFeedFolder
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
fldr = mgr.RootFolder
ListFeeds(fldr)
End Sub
Private Sub ListFeeds(ByVal fldr As IFeedFolder)
For Each feed As IFeed In fldr.Feeds
Trace.WriteLine(feed.Name)
ListItems(feed)
Next
For Each f As IFeedFolder In fldr.Subfolders
Trace.WriteLine(f.Name)
ListItems(f)
Next
End Sub
Private Sub ListItems(ByVal feed As IFeed)
Trace.Indent()
For Each...
Vista: File System Transactions
Windows Vista has several new functions for using transactions when working with files. Here is an example on how to create a transaction, work with some files, and commit it.
Imports System.Runtime.InteropServices
Imports Microsoft.Win32.SafeHandles
Imports System.IO
Module Module1
Public Declare Auto Function CreateTransaction Lib "Ktmw32.dll" (ByVal Attributes As IntPtr, _
ByVal guid As IntPtr, ByVal options As Integer, ByVal isolationlevel As Integer, _
ByVal isolationflags As Integer, ByVal milliseconds As Integer, ByVal description As String) As IntPtr
Public Declare Auto Function RollbackTransaction Lib "Ktmw32.dll" (ByVal handle As IntPtr) As Boolean
Public Declare Auto Function CommitTransaction Lib "Ktmw32.dll" (ByVal handle As IntPtr) As Boolean
Public Declare...
Draw an Icon in a DataGridViewButtonCell
Here is a simple example on how to draw in a DataGridViewButtonCell. In this example an icon is displayed when button is pushed and the icon is made invisible when its pushed again. I am storing the if the button has been pressed in the cell's tag. I use the cellPainting event to draw the icon when needed.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace CSButtonColumn
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
String strConn = "Server = .\\SqlExpress;Database =...
I've been Tagged: Five Things You Might Not Know About Me
I have been tagged by Shawn Weisfeld. Here are 5 things you might not know about me.
1) My son Ryan, brother Denis and I are all Eagle Scouts
2) I love to go camping. I have a lot of good memories backpacking upstate New York.
3) My current job is an assistant engineer onboard Sun Cruz's Surfside Princess
4) I have 4 dogs, 4 cats, and 3 birds as pets.
5) While working on ships I have visited England, Scottland, Ireland, Germany, Norway, Spain, Canada, Puerto Rico, UAE, and Bahrain.
SQLCLR: Create a custom function
I store a persons full name in the name field of one my sql express database which I wanted to sort by the last name. Well I could always try a query like this.
SELECT * FROM SPEAKERS ORDER BY SUBSTRING(NAME, PATINDEX('% %', NAME), LEN(NAME) + 1 - PATINDEX('% %', NAME))
Unfortuntely some of the names have a middle initial so this method was not fool proof. This is where SQLCLR came to the rescue. By creating a SQL Server Project you can create functions with VB.Net code. So lets create a Sql Server Project and right click on the Project Name...
Inner Join with 2 or more tables
If you are getting data from more than 2 tables you need to surround the inner joins in brackets. For this example I am using the just released SQL Compact Edition. You will find a sample NorthWind database in the sdk. Note to work with a SQL CE database you need to add a reference to the System.Data.Sqlce.dll you find in the directory you installed sql server ce.
Imports System.Data.SqlServerCe
Imports System.Text
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As New SqlCeConnection("data source='NorthWind.sdf'; mode=Exclusive;")
Dim...
Unable to Update Database added to Project
I see from time to time people complaining they can not update an database they added to their Visual Studio 2005 project. Sometimes your database is actually getting updated but Visual Studio is copying the old version of the database over the updated version. You should check and make sure the Database's Copy to Output property is not set to Copy Always. It should be set to Copy if newer.
Vista Application Recovery
Ever want to add the ability to recover the user data if your application has crashed. Windows Vista has some nice apis to make this easy.
The RegisterApplicationRestart api tells Vista we would like the app to restart if it crashes or hangs. This api takes two arguments a string which will be the command line argument when the application restarts and RestartFlags. For this example we will tell the app to always restart. Note the app must run 60 seconds before it will restart.
Enum RestartFlags
Always = 0
Cyclical = 1
NotifySolution = 2
NotifyFault...
UpdatePanel Gotcha
Do not update the contents inside a UpdatePanel with java script. You will not get the resuts you expect.
For example place a span and button inside an update panel.When you click on a button control the java script onClientClick will fire followed by the Click event for the button. So if we update the span's text with onClientClick the text will update briefly then the UpdatePanel will catch the post back made by the click event and erase our changes.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%@ Register Assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="Microsoft.Web.UI" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD...
Datagrid Validation
The DataGridView has a CellValidating Event to validate the data entered. Here is how to do it with the DataGrid.
There are 2 method to do this. My method is to add a tablestyle to the datagrid. For the cells I want to validate I handle the DataGridTextBoxColumn's Textbox's Validate event. George Shepherd's method is use the CurrentCellChanged event. You can read about this method in the Windows Forms FAQ.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace CSDatagrid
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
...
Printer Compatibility Library 1.0
Visual Basic 6.0 and earlier had a printer object which made it simple to print. The Printer Compatibility Library 1.0 makes it possible to use the same object with VB or C# 2005. After installing the Power Pack just add a reference to Microsoft.VisualBasic.PowerPacks.Printing.Printer
VB Sample
Imports Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim p As New Printer
p.Print("Page 1")
p.NewPage()
p.Print("Page 2")
p.EndDoc()
End Sub
End Class
C# Sample
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6;
namespace PrinterCS
{
public partial class Form1 : Form
{
public Form1()
{
...
Data From Multiple Tables in a DataGridView
There is Msdn Knowledge base article which shows how to create a JoinView class. The JoinView class is for joining 2 tables together for data binding. Basically you load 2 or more tables into a dataset and set up some data relations for the related tables. When you create the Joinview the first argument is the main table, 2nd is a list of fields you want to show, 3rd is a filter, and 4th is the field to sort on. The last 2 arguments are option. Since the article includes a vb sample I...
WPF: DataBind a ListView
There is not a DataGrid or DataGridView in Windows Presentation Foundation. Use the ListView to display data in a table. In the window's Xaml define the listview and the fields you want displayed. The code behind file is where you get the data from the Northwind database and bind the listview.
The Windows Xaml
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WPF1" Height="300" Width="300"
>
<Grid>
<ListView Margin="25,22,30,48" Name="ListView1" >
<ListView.View>
<GridView >
<GridViewColumn Header ="Last Name" DisplayMemberBinding="{Binding LastName}" Width="100"></GridViewColumn>
<GridViewColumn Header ="First Name" DisplayMemberBinding="{Binding FirstName}" Width="100"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
</Window>
The Code Behind
Imports System.Data
' Interaction logic for Window1.xaml
Partial Public Class Window1
Inherits System.Windows.Window
Public Sub...
AutoComplete in DataGridView
In the datagridview's editing control showing event you have better access to the textboxes properties. Here is an example of adding autocomplete to the textbox.
VB Sample
Imports System.Data.SqlClient
Public Class Form1
Dim scAutoComplete As New AutoCompleteStringCollection
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strConn As String
Dim da As SqlDataAdapter
Dim conn As SqlConnection
Dim ds As New DataSet
strConn = "Server = .;Database = NorthWind; Integrated Security = SSPI;"
conn = New SqlConnection(strConn)
da = New SqlDataAdapter("Select * from [Orders]", conn)
da.Fill(ds, "Orders")
DataGridView1.DataSource = ds.Tables("Orders")
Dim cmd As New SqlCommand("Select...
.Net Framework 3.0 Text to Speech
The dot net framework 3.0 now has a managed provider for text to speech. I tested this app on a machine with windows xp service pack 2 and the Dot Net FrameWork 3.0 RC1. The link is to set up instructions for the .net framework 3.0
For this sample add a reference to system.speech, place a textbox named txtSay, a button named btnSay, and listbox named lstVoice. The application fills a list box with the installed voices on the system at startup. When you click on the button it says the text in the textbox...
Beta Certification Exam
I took the beta exam for Microsoft Windows Mobile 5.0 - Application Development (exam number 70-540) with the visual basic option. The exam had 81 questions with a 4 hour time limit. There was one c# question slipped in there.
There were questions on the creating menus, smart phone connection status to the network, interacting with contact list, listing items in the task list, serial port, xml, and httpwebrequests.
SQL Everywhere (formerly SQL Mobile) was a topic which had a few questions. You will need to know how to repair a database, and sync with a sql 2005 database....
Secure Strings
The SecureString is a new class that was added in the .Net framework 2.0 which allows you to store info in memory securely. The SecureString could be used to safely secure a password or credit number. The example shows how to add info to the string, prevent changes from being make to the data, and finally how to get the info back. I included c# and VB samples.
C# sample
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security;
using System.Runtime.InteropServices;
namespace SecureStringCS
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
...
Predicates
I recently read an article in the MSDN magazine about Predicates and Actions written by Ken Getz. I was thinking that predicates will make it easy to create a master details datagridview for a business object. This example creates 2 classes Customers and Orders. I used the Northwind database to fill a list of customers and a list of orders. I bound one grid to a binding source who's datasource is the list of customers. In the binding sources position changed event I use the list of orders findall method to show all the orders for a customer.
The classes...
Create a Pivot Table
Here is a quick example on how to rotate or pivot the data in a datagridview. This is a c# program which creates a new data table with a rotated version of the data to bind to. There is a VB version on the vb-tips website.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Pivot
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DataTable dt1;
private void Form1_Load(object sender, EventArgs e)
{
dt1 = CreateTable();
DataTable dt2 = new DataTable("Reflected");
for (int i = 0; i < dt1.Rows.Count; i++)
{
dt2.Columns.Add(i.ToString());
...
Use LogParser with VB.Net
There are times I would like to get information from the log files of a website and display them on a web form or windows form. I created a simple sample which uses the logparser dll. I added a reference to logparser.dll in the program files\log parser 2.2 folder. You can download log parser here.
Imports MSUtil
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As DataTable = parseLog("select c-ip, count(c-ip) as visits from c:\W3SVC525089654\ex*.log where cs-uri-stem like '%.aspx' group by c-ip order by visits desc")
DataGridView1.DataSource = dt
...
DataGridView Grouping
Several people in the msdn forums have asked how to make groupings more noticable in the datagridview. Here is my solution
Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
Dim strConn As String
Dim da As SqlDataAdapter
Dim conn As SqlConnection
strConn = "Server = .;Database = NorthWind; Integrated Security = SSPI;"
conn = New SqlConnection(strConn)
da = New SqlDataAdapter("Select CategoryID, ProductName, UnitPrice from Products Order By CategoryID", conn)
da.Fill(dt)
dt.Columns("CategoryID").DefaultValue = 6
DataGridView1.DataSource = dt
DataGridView1.Rows(0).DefaultCellStyle.BackColor = Color.SkyBlue
End Sub
Private Sub DataGridView1_CellFormatting(ByVal sender...
Extend the Table Adapter
The table adapter is missing some events and properties that the data adapter has. Fortunately the tableadapter class is a partial class that uses a data adapter. This makes it easy to add properties or events to it. For this example I opened the data sources window and created a data source to the Adventure Works Employees table. I dropped the table on a form. The dataset is named AdventureWorksDataSet and the table adapter is EmployeeTableAdapter. The table adapter is in the DataSetNameTableAdapters name space. For our example it is AdventureWorksDataSetTableAdapters. The table adapter class has a...
Make a Datagridview move to the next cell on Enter
To make a datagridview move to the next column when you press the enter you need to create a new control which inherits from datagridview. In the new control override PreProcessMessage to prevent the default enter key behavior. I also created a new column which converts an enter press to a tab key. Here is a simple c# example. A VB 2005 example is available on the VB-Tips website.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace EnterNextCell
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
...
DatagridView ProgressBar Column
Here is a c# example on how to create a progress bar column for the datagridview. You can find a VB example on the VB-Tips website.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace csProgressBarColumn
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ProgressColumn col = new ProgressColumn();
dataGridView1.Columns.Add(col);
dataGridView1.AllowUserToAddRows = false;
dataGridView1.RowCount = 5;
int x = 1;
foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
row.Cells[0].Value = x*20;
x++;
}
}
}
}
public class ProgressColumn : DataGridViewColumn
{
public ProgressColumn():base(new ProgressCell())
{
}
public override DataGridViewCell CellTemplate
{
get
...
Encrypting Data
Here is a vb2005 example on how to encrypt and decrypt data. I am storing the encryption key as a base64 string in the programs settings. The settings name is Key and its starting string value was Unknown. In a production application I would store it in a more secure location.
Imports System.Security.Cryptography
Imports System.IO
Imports System.Text
Public Class Form1
Public Key() As Byte
Public IV() As Byte
Public Function Encrypt(ByVal strData As String) As Byte()
Dim data() As Byte = ASCIIEncoding.ASCII.GetBytes(strData)
Dim tdes As TripleDESCryptoServiceProvider = _
New TripleDESCryptoServiceProvider
If Key Is Nothing Then
tdes.GenerateKey()
tdes.GenerateIV()
Key = tdes.Key
IV =...
Tampa Code Camp
I did a session at the Tampa code camp on the datagridview. I covered sorting, changing column types, cell format event, sql dependency, and exporting to spread sheets.
Download the powerpoint and sample code.
Get the right row from a sorted DataGridView
When a datagridview is bound to a datatable you need to use the datatable's defautview to find the right record after the grid has been sorted.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace CsharpRow
{
public partial class Form1 : Form
{
DataTable dt;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
String strConn = "Server = .;Database = NorthWind; Integrated Security = SSPI;";
SqlConnection conn = new SqlConnection(strConn);
SqlDataAdapter da = new SqlDataAdapter("Select * from Products", conn);
dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource=dt;
}
private void...
Binding a Datagridview and binding navigator with code
Here is a c# example on how to bind a datagridview and bindingnavigator with code. I manually added the save button to the bindingnavigator.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace CSharpBindingSource
{
public partial class Form1 : Form
{
SqlDataAdapter da;
SqlConnection conn;
DataSet ds;
BindingSource bs;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
String strConn = "Server = .;Database = NorthWind;Integrated Security = SSPI;";
conn = new SqlConnection(strConn);
da = new SqlDataAdapter("Select * From Employees", conn);
SqlCommandBuilder cmd = new SqlCommandBuilder(da);
...
Tallahassee Code Camp
I did a session on the DataGridView and DLinq at the Tallahassee code camp today. You can find the power point slides and sample code at the vb-tips website's new code camp section.
Atlas Tool Kit
The atlas tool kit is truely awsome. I see there is an error in collapsiblepanelextender documentation. The sample code on the webpage shows the expanddirection as height when the valid values are horizontal and vertical. It also shows openedsize instead of expandedsize.
<atlasToolkit:CollapsiblePanelExtender ID="cpe" runat="Server">
<atlasToolkit:CollapsiblePanelProperties ExpandedSize="200" TargetControlID="pnlRss"
ExpandControlID="LinkButton1" CollapseControlID="LinkButton1" Collapsed="True"
TextLabelID="LinkButton1" CollapsedText="Show Details..." ExpandedText="Hide Details..."
SuppressPostBack="true" />
</atlasToolkit:CollapsiblePanelExtender>
<asp:Label ID="lblRss" Text="Whats New in VB-Tips" runat="server"></asp:Label>
<asp:LinkButton ID="LinkButton1" runat="server" Text="Show Details..">
</asp:LinkButton>
<asp:Panel ID="pnlRss" runat="server" Width="100%" ScrollBars="Vertical">
<asp:DataList ID="DataList1" runat="server" BackColor="White" BorderColor="#E7E7FF"
BorderStyle="None" BorderWidth="1px" CellPadding="3" DataSourceID="RssDataSource1"
GridLines="Horizontal">
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<ItemTemplate>
<asp:HyperLink...
DXCore
Developers express has a free product DX Core. It is a framework to develop add ins for visual studio. With it you can paint on the ide, work with the text, etc.
I answer alot of questions in the newsgroups and forums. From time to time I copy code from the ide and when it pasted it looses the format. To overcome this limitation I usually paste the text in notepad. I then recopy the text and paste it in the question I am answering to preseve the format.
Today I used the dxcore to add the copy as text...
Find Duplicate Records in a Datatable
I was asked how to find duplicate records in a datatable, I used a dataview to sort my records. I used the sorted list to check the next record for a duplicate record. The duplicate will be deleted.
Imports System.Security.Cryptography
Public Class Form1
Dim dt As New DataTable
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dt.Columns.Add("Name")
dt.Columns.Add("Number", GetType(Integer))
For x As Integer = 0 To 200
Select Case x Mod 3
Case 0
dt.LoadDataRow(New Object() {"Ken", TrueRandom.Rand(100)}, True)
Case 1
dt.LoadDataRow(New Object() {"Kelly", TrueRandom.Rand(100)}, True)
Case 2
dt.LoadDataRow(New Object() {"Bill", TrueRandom.Rand(100)},...
SQL Server 2005 SP 1 help
From my partner Kelly Martins at KJM Solutions
If this error occurs here is what worked for me. I hope it may work for you but am not sure.
In my case I had SQL Express 2005 Installer on my system as well as I run both (one for development, one for production).
Shut down all SQL related services manually.
I set registry permissions on Software\Policies\Microsoft\Windows\Installer to include the account that is doing the install with Full Control. Click Advanced and make sure everything is selected.
I downloaded and ran the SQL Install Cleanup and...
Virtual Server 2005 R2 Now free
Microsoft has now made Virtual server 2005 R2 a free product. You can download Virtual Server 2005 R2 here.
Tom Fuller MVP
Congradulations to my friend Tom Fuller on making Solution Architect MVP. Tom runs the Soa Pitstop website. Tom also speaks at florida code camps and user group meetings.
SQL Everywhere
Microsoft will be removing the restrictions on sql sever 2005 mobile edition so it works in a desktop environment. Check out the SQL everywhere FAQ on Steve Lasker's blog
VB 2005 Performance issues Hotfix
A hot fix that addresses some performance issues with Visual Basic 2005 has been released.If you are having the problems listed in the KB article call PSS (Product Support Services) 800-936-4900 and tell Technical Routers that they want to be transferred to Developer Support, Visual Basic team, it would expedite the call. Request the hot fix described in KB Article 917452. The KB article is not available yet.
Atlas April Ctp Released
The April CTP of Atlas was released today. Along with a toolkit that has some cool tools.
Web Control Issue
I was playing around with creating a web control you can add to the toolbox. To create this I started with a VB 2005 class library project. I added a reference to the system.web. I added a bitmap to the project and set its build action to embedded resource. I also set the tagprefix for the control. Here is the issue. If I set the namespace in the project properties everything works as expected. If set the namespace the toolbox bitmap and tag prefix do not work .
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Drawing
<Assembly: System.Web.UI.TagPrefix("MyControls", "kens")>
<ToolboxBitmap(GetType(MyWeatherSticker), "Arrow.bmp")> _
<ToolboxData("<{0}:MyWeatherSticker...
More WMI events
I was playing around with using the wmi _InstanceModificationEvent. I created a sample which will keep an acurate list of the screen size. Like all wmi programs you need to add a reference to system.management for this to work. My sample requires a listbox on a form.
Imports System.Management
Public Class Form1
Dim WithEvents w As ManagementEventWatcher
Dim q As WqlEventQuery
Delegate Sub LoadList()
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
w.Stop()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
q = New WqlEventQuery
q.QueryString = "SELECT...
Dynamic Help Window in VB Express
The Dynamic Help window is not supported in visual basic express.
Dot Net User Group
My local computer club SCTPA folded today. I am trying to start a dot net user group in Brevard county Florida. Any one interested in joining should send me an email.
Sql Server 2005 Service Pack 1
I see there is a CTP for a Sql Server 2005 service pack available. Here is a link for anyone interested.
Atlas March Ctp Released
The March CTP of Atlas was released today. It is the first version of Atlas to have a go live license.
Custom Sort of DataGridView
Someone asked me about doing a custom sort on a datagridview during my datagridview session at code camp. Unfortunately this will not work if the datagridview is bound to a datasource. This example numbers as string data to a datagridview. When you sort this column the values will not be in numeric order. This example converts the string to a number and sorts based on the number.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataGridView1.ColumnCount = 1
DataGridView1.Columns(0).HeaderText = "String"
For x As Integer = 0 To 100
DataGridView1.Rows.Add(New...
Async DataGridView fill Issue
Here is an issue brought up by fellow MVP Jose Fuentes. When filling a data table asyncronously bound to a datagridview you will wind up with a blank line in the datagridview. To get around this issue do not set the datasource until the data table is filled.
Public Class Form1
Dim dt As New DataTable
Delegate Sub ReloadGrid(ByVal dt As DataTable)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dt.Columns.Add("Column1")
dt.Columns.Add("Column2")
' comment out the next line to load grid properly
DataGridView1.DataSource = dt
Me.FillDALViaThread(dt, Me)
End Sub
Public Sub FillDALViaThread(ByRef DT...
New Website
Upgraded the website today to use the asp.net 2.0. I used the small business template from the asp.net website for the site look. Posted it on the KJM Solutions server. I am using SQL Server 2005 for the blog now. We are getting closer to opening up for business.
Restore SQL 2005 Database
You can use the smo restore class to restore a sql server 2005 database. SqlExpress databases must be restored from the sql express directory. This sample restores the northwind database backed up in my last blog entry. You need to add a reference to Microsoft.SQLServer.SMO for this sample to work.
Using SMO with Sql Express
Imports Microsoft.SqlServer.Management.Smo
Module Module1
Sub Main()
Dim svr As Server = New Server(".\SQLEXPRESS")
Dim rst As Restore = New Restore
Dim strPath As String = svr.Information.MasterDBPath
strPath = strPath.Replace("\DATA", "\Backup\Nwnd.Bak")
rst.Devices.Add(New BackupDeviceItem(strPath, DeviceType.File))
rst.Database = "Northwind"
rst.ReplaceDatabase = True
Try
rst.SqlRestore(svr)
...
Backup SQL 2005 Database
You can use the smo backup class to backup a sql server 2005 database. SqlExpress databases must be backed up to the sql express directory. You need to add a reference to Microsoft.SQLServer.SMO for this sample to work.
Using SMO with Sql Express
Imports Microsoft.SqlServer.Management.Smo
Module Module1
Sub Main()
Dim svr As Server = New Server(".\SQLEXPRESS")
Dim bkp As Backup = New Backup()
Dim strPath As String = svr.Information.MasterDBPath
strPath = strPath.Replace("\DATA", "\Backup\Nwnd.Bak")
bkp.Action = BackupActionType.Database
bkp.Database = "NorthWind"
Dim bdi As New BackupDeviceItem(strPath, DeviceType.File)
bkp.Devices.Add(bdi)
Try
bkp.SqlBackup(svr)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Module
Module...
Real Random Numbers
The random function does not generate truely random numbers. Use the RNGCyptoServiceProvider to create them
Imports System.Security.Cryptography
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FillList()
End Sub
Private Sub FillList()
ListBox1.Items.Clear()
For x As Integer = 0 To 20
ListBox1.Items.Add(TrueRandom.Rand(500).ToString)
Next
End Sub
Private Sub btnNewList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewList.Click
FillList()
End Sub
End Class
Public Class TrueRandom
Public Shared Function Rand(ByVal MaxNum As Integer) As Integer
Dim rnd(20) As Byte
Dim num As Long
Dim generator As New RNGCryptoServiceProvider
generator.GetBytes(rnd)
For x As Integer = 0 To...
VB 2005 Complier Hotfix
There was a hot fix released for the VB 2005 complier problem described here. If you are having the problems listed call PSS (Product Support Services) 800-936-4900 and tell Technical Routers that they want to be transferred to Developer Support, Visual Basic team, it would expedite the call. Ask about getting the patch for KB# 915038.
USB drive insert notification
The wmi supports events. I use the instance creation event for the Win32_LogicalDisk for the notification. Add a reference to the system.management for this sample. You need a form with a listbox for the code to work.
Imports System.Management
Public Class Form1
Dim WithEvents w As ManagementEventWatcher
Dim q As WqlEventQuery
Delegate Sub LoadList()
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
w.Stop()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
q = New WqlEventQuery
q.QueryString = "SELECT * FROM" & _
" __InstanceCreationEvent WITHIN 1 "...
Got Code?
Orlando .NET CodeCamp Saturday, March 25 2006
Here is a list of the topics
3D For the Rest of Us (Avalon/WPF)
7 Ways to Ajax
ASP.NET 2.0 Membership and Role Management
An In-depth look at Profiles in ASP.NET 2.0
A guide to developing Web Server Controls
Accessible Web Applications (Section 508)
Building new apps with ATLAS - Smart Client Application Development & Deployment
Customizing the Windows Forms DataGridView
Generic Database Programming with ADO.NET
DotNetNuke Chalk Talk / BOF
Developing Custom Modules the easy way with code generation and freely available tool
Introduction to the DotNetNuke portal framework (part 1)
Introduction to the DotNetNuke...
KJM Solutions
KJM Solutions is now open for web hosting. We offer .NET Framework 1.1 and .NET Framework 2.0, ASP.NET, application hosting and web services hosting. 1 GB Disk Space divided among all services as you choose, 350GB Monthly Data Transfer, Unlimited POP3 Email Accounts, Unlimited Microsoft SQL Server 2005 Databases, Unlimited Microsoft SQL Server 2000 Databases, Unlimited FTP Accounts, Unlimited Email Forwards, Frontpage 2002 Extensions, 24/7 Email Support, Web Based Email for $35.00 per month. The first 3 months are free.
Contact Sales for more info.
Find Missing dll
There was a question the other day in the vb.net newsgroup on how to make a list of the missing dlls on your system. Files that are registered by regsvr32 create a CLSID. This program will check all the CLSID registered dll exists and adds the missing ones to a list box.
Imports Microsoft.Win32
Imports System.IO
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
...
Code Camp
I went to the Code Camp in Tallahassee and did a session on Windows Forms Datagrid. I talked about the new features in VS.Net 2005 and customizing the datagrid. You can find the most of the code on my Datagrid help website. If you have any questions please feel free to email me.
Blog up and running
Well I got my blog up and running today. I am using a MySql database for storing the data. My web host brinkster offers Sql Server, MS Access, and MySql database storage. I seam to get a lot of data access errors using MS Access on the web when I have too many users at once. I figured I will try the MySql. Seams to be a very powerfull database full of features. I still prefer to use Sql Server.
In addition to this site I also maintain a VB.Net and VB-Tips website with Cor Ligthert. I am...
Image Buttons
I have been working on making image buttons that change color when the mouse is over them. I have created transparent gifs using vb.net for the buttons. I use a transparent background because the image will display the background color of the image button. I change the backcolor with java script.
The code I used to create the transparent gif is based on code from Bob Powells
GDI+ FAQ
Binding to a WPF Listbox Part 1
Binding to a WPF Listbox is a lot more flexible than binding to a Windows Form listbox. In the WPF Listbox you need to define a DataTemplate which tells the Listbox how to display the data. For this example we will create an Animals class and display the data in a Listbox.
Pages XAML
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<DataTemplate x:Key ="lstItem" >
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="75" />
<ColumnDefinition Width="75" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Path=Animal}" Grid.Column="0" />
<TextBlock Text="{Binding Path=Species}" Grid.Column="1" />
</Grid>
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid>
<ListBox Margin="14,15,47,34" Name="ListBox1" ItemTemplate="{StaticResource lstItem}" >
</ListBox>
</Grid>
</Window>
The Code
Class Window1
Private Sub Window1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
...
MySql Full Text searches
You must create a table that uses the MyISAM engine to support full text searches in MySql. Here is an example on how to create the table.
conn = New MySqlConnection(strConn)
conn.Open()
Dim sbCmd As New System.Text.StringBuilder
sbCmd.Append("Create Table If Not Exists MyBlog ")
sbCmd.Append("(PostDate DateTime NOT NULL PRIMARY KEY, ")
sbCmd.Append("BlogEntry Text, FullText(BlogText))")
sbCmd.Append(" Engine = MyISAM")
cmd = New MySqlCommand(sbCmd.ToString, conn)
cmd.ExecuteNonQuery()
conn.Close()
Use the MySql Match Against query to preform a full text search
Match Against Query Info
Using Linq for Master Detail in a DataGridView
I saw in the MSDN forums someone asking how to do a master details relationship with Linq. It is actually pretty simple. Here are the steps involved on creating the relationship. I am using VS 2008 Beta 2 for this example.
Open up Visual Studio 2008 Beta 2 and create a windows forms Application
Add a new Linq 2 Sql classes to the project named Northwind.dbml
Drag the Northwind database's Orders and Order Details table onto the surface
Save the project and build it
Open the data sources window and add a new object data source. Select...