Monday, September 30, 2013

DatagridView Tutorial with DataGridViewButtonCell

DatagridView Tutorial with DataGridViewButtonCell

I have shown you how to quickly learn to use a DataGridView. How to insert? How to delete? How to do basic operation?  In that first post, you used the DataGridViewTextBoxColumn.  Reading that tutorial is like making a MS-Access or a MS-Excel. Now is time to enhance a little bit your DataGridView using button inside you table. Again, there is nothing to hard to start with.

Lesson 5: Using DataGridViewButtonCell

From the Visual Basic form Designer, simple add a column and make sure you choose the DataGridViewButtonCell type. Named your column like cButton and give a good description like BUTTON.
Because the Button cell is no ordinary cell, I have to detect it.
The easiest way is by getting the column index. Here is a very short example and I highlighted the important part. Using a regular if condition, if the column index from the CellMouseClick is the same number of the cButton index, then we got our DataGridViewButtonCell object.
My example above simple change the color of the button after a click, change the style and deselect the button object. Fell freer to do some general testing.

Download the sample project

All the functions and the step use in this post are inside the sample project. Fell free to take a look at it. When you start the sample project, an initial DataGridView will be filled with random numbers. A save function is called if you close the WinForm.
When you click on a button inside the DataGridView, you will notice it will change color to yellow.


    Private Sub DataGridView1_CellMouseClick(sender As Object, e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
        If e.Button = Windows.Forms.MouseButtons.Right Then
            Me.Text = ("[" & e.RowIndex & " ; " & e.ColumnIndex & "]")
            Dim pt As Point = MousePosition
            ContextMenuStrip1.Show(pt)
        ElseIf e.Button = Windows.Forms.MouseButtons.Left Then
            Dim dgvbc As DataGridViewButtonCell
            If e.RowIndex > 0 AndAlso e.ColumnIndex > 0 Then
                If e.ColumnIndex = cButton.Index Then
                    dgvbc = Me.DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex)
                    dgvbc.FlatStyle = FlatStyle.Flat
                    dgvbc.Style.BackColor = Color.Yellow
                    dgvbc.Selected = False
                End If
            End If
        End If
    End Sub

References:

Previous post : DatagridView Tutorial

Wednesday, September 25, 2013

DataGridView Tutorial

DataGridView Tutorial

Learn to use a DataGridView in 5 minutes.  A sample project is provided to help. In this tutorial, I will give you some tips and some advice. It will be a crash course. At the end, you will have enough to learn by your own. I will do it in visual basic and I will use a WinForm Application to quickly cover the most of the subject and skip the boring stuff.

Tuesday, September 24, 2013

BlackBerry to Sell

BlackBerry to Sell


Fairfax Financial offers 4.7 billions of Canadian dollars to the Canadian company Blackberry. This is good news because it is a floor price. The deal stands until November 2013 and Blackberry could have better deals.
If I were at their shoes, I wouldn’t wait too long. I would take the cash and move on. When we look at BlackBerry for the last few years, we understand how important for that Canadian company to renew itself. The effort was good for the last 2 years, but not enough.

There was a time; BlackBerry was the leader in telecommunications. Stocks reach 145$ at that time.

How could we explain this failure? What could we reasonably learn from this situation?

Thursday, September 12, 2013

MDB and ACCDB file searcher.

MDB and ACCDB file searcher.

Find all MS-Access files from a directory and display them on your screen. Here is a sample code in vb. At first, I might be pretty useless because Windows do have a file searcher but what if you want to do some operation over each file? That is why this sample code might be useful for you.
I also include a dynamic tooltip MouseMouve for the ListBox and very basic functions to make this program more enjoyable.
You could download the project sample at the end of this post.
MDB and ACCDB file searcher

Backup AutoCAD profile tool


Where could I find a good backup AutoCAD profile tool for free? The one from AutoCAD (Autodesk) doesn’t export everything. The ARG file only exports the settings. The CUIX file only exports some other type of setting. I have to do like 10 operations to backup a profile and transfer it on another computer.  Is there something easy to use?  Forget about the one under the Start Menu and All programs.

Tuesday, September 10, 2013

Read XML File

Read XML File

Example in visual basic of XML reader

Here is and example of code to read a very basic XML file. It uses XmlTextReader to circle over each XML elements. This code also uses XmlNodeType to differentiate the type of information inside the XML file.

The code is simple and has basic security precaution. It checks if the file exist. I also use Fileinfo to keep the filename instead of a regular string. With the Fileinfo object, I could have the file size and other useful information in case something goes wrong in the reading.

Friday, September 6, 2013

Get Table Names from Access using VB

Get Table Names from Access using VB


Use Visual basic .NET to get tables names from MS-Access (Microsoft MS Access) with OleDbConnection and “Microsoft.Jet.OLEDB.4.0” or “Microsoft.ACE.OLEDB.12.0”.
Table MS-Access


Here is an example of code in Visual Basic 2010:

Tuesday, September 3, 2013

Best programming language for AutoCAD

Best programming language for AutoCAD


VB.NET, C#.NET, macros, scripts, LISP, VBA, and C++, are all tools available in AutoCAD for software development.  What to choose is not always easy. Base on “Through the Interface” written in 2008, I will try to review the pros and the cons on every programming language available.
In 2008, Microsoft was already capable to offer a good framework and good editing tools such as Microsoft Visual Basic 2008 and Microsoft Visual c# 2008 but AutoCAD and Autodesk haven’t offer a mature .NET API. Also, not everyone could learn a new programming language or switch from on technology to another.
In 2013, it never had been to true that .NET will suppress old programming language such as LISP, C++, VBA.