Author Archives: Hasan Bazerbashi

About Hasan Bazerbashi

My name is Hasan Bazerbashi graduated from New York Institute of Technology with B.Sc. in Computer Science. I’m the kind of guy who loves the Computer and everything about it and about Technology. And let’s not forget about Robots! I do .NET programming, and have lot of projects I’ve done using it and lot in my mind that I want to do using this great technology. As for my hobbies, I like taking photos and learning about photography and still an amateur photographer, also I enjoy playing video games from time to time, and of course watching movies and listening to Music.

Editable bound DataGridView ComboBox

A bound DataGridView ComboBox Column doesn’t allow user input. You might come across a situation where you need to make it easier for the user to select an item from the ComboBox and at the same time allow them to just enter free text.

The trick is to make the ComboBox column without a DataSource and then you load the items by code. Also you have to handle a couple of stuff such as the EditingControlShowing event to convert the ComboBox style to be DropDown instead of DropDownList, and some other handling to commit the ComboBox change.

I will leave you with the code:
[vb]Private Sub MyForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    ‘Get ComboBox items
    Me.ComboBoxTableAdapter.Fill(Me.MyDataSet.ComboBoxTable)

    ‘Fill the ComboBox
    Dim row As DataRow
    For Each row In Me.MyDataSet.ComboBoxTable
        ‘Generic list used as a trick to have the ComboBox Items added with Value
        MyComboBox.Items.Add(New GenericListItem(Of String)(row.Item("ColName"), row.Item("ColValue")))

    Next

    Me.GridTableAdapter.Fill(Me.MyDataSet.GridTable)

    ‘Adding Grid handler to detect change in run time
    AddHandler MyDataGridView.CurrentCellDirtyStateChanged, AddressOf MyDataGridView_CurrentCellDirtyStateChanged

End Sub

‘Change ComboBox style to DropDown
  Private MyDataGridView_EditingControlShowing(ByVal sender As Object, ByVal e As MyDataGridViewEditingControlShowingEventArgs) Handles MyDataGridView.EditingControlShowing
        If TypeOf e.Control Is ComboBox Then
Dim cb As ComboBox = TryCast(e.Control, ComboBox)

            cb.DropDownStyle = ComboBoxStyle.DropDown
        End If

‘When an item is selected from the ComboBox update the cell value
        If MyDataGridView.Columns(MyDataGridView.CurrentCell.ColumnIndex).Name = "MyComboBox" Then
Dim selectedComboBox As ComboBox = DirectCast(e.Control, ComboBox)
            RemoveHandler selectedComboBox.SelectionChangeCommitted, AddressOf selectedComboBox_SelectionChangeCommitted
            AddHandler selectedComboBox.SelectionChangeCommitted, AddressOf selectedComboBox_SelectionChangeCommitted

        End If

    End Sub

Private Sub selectedComboBox_SelectionChangeCommitted(ByVal sender As Object, ByVal e As EventArgs)
    Try

        Dim selectedCombobox As ComboBox = DirectCast(sender, ComboBox)
        If selectedCombobox.SelectedItem IsNot Nothing Then

            ‘Use the List we created earlier so we could retrieve the Value instead of the diplayed text
            Dim oItem As GenericListItem(Of String) = CType(selectedCombobox.SelectedItem, GenericListItem(Of String))

            Me.MyDataGridView.Item("ColumnName", MyDataGridView.CurrentCell.RowIndex).Value = oItem.Value()

        End If

    Catch ex As Exception
        MessageBox.Show(ex.Message)

    End Try
End Sub

Private Sub MyDataGridView_CurrentCellDirtyStateChanged(ByVal sender As Object, ByVal e As EventArgs) Handles MyDataGridView.CurrentCellDirtyStateChanged
    ‘Commit the change which was in run time so the Value changed event happens and then allow one check box
    If MyDataGridView.IsCurrentCellDirty Then
        MyDataGridView.CommitEdit(MyDataGridViewDataErrorContexts.Commit)
    End If
End Sub

Private Sub MyDataGridView_CellValidating(sender As Object, e As System.Windows.Forms.MyDataGridViewCellValidatingEventArgs) Handles MyDataGridView.CellValidating

    ‘Allow user to enter new values for all MyDataGridViewComboBox controls in the MyDataGridView
    If (TypeOf CType(sender, MyDataGridView).EditingControl Is MyDataGridViewComboBoxEditingControl) Then
        Dim cmb As MyDataGridViewComboBoxEditingControl = CType(CType(sender, MyDataGridView).EditingControl, MyDataGridViewComboBoxEditingControl)
        If Not cmb Is Nothing Then
            Dim grid As MyDataGridView = cmb.EditingControlMyDataGridView
            Dim value As Object = cmb.Text
            ‘// Add value to list if not there
            If cmb.Items.IndexOf(value) = -1 Then
                ‘// Must add to both the current combobox as well as the template, to avoid duplicate entries…
                cmb.Items.Add(value)
                Dim cmbCol As MyDataGridViewComboBoxColumn = CType(grid.Columns(grid.CurrentCell.ColumnIndex), MyDataGridViewComboBoxColumn)
                If Not cmbCol Is Nothing Then
                    cmbCol.Items.Add(value)
                End If
            End If
            grid.CurrentCell.Value = value
        End If
    End If

    ”Following Works for a specific combobox ///////////

    ‘If e.ColumnIndex = MyMyDataGridView.Columns("MyDataGridViewComboBoxColSize").Index Then ‘CType(sender, MyDataGridView).CurrentCell.ColumnIndex

    ‘ ‘Dim cmb As ComboBox = CType(e.Control, ComboBox)

    ‘ Dim cmb As MyDataGridViewComboBoxEditingControl = CType(CType(sender, MyDataGridView).EditingControl, MyDataGridViewComboBoxEditingControl)

    ‘ If Not cmb Is Nothing Then

    ‘ Dim grid As MyDataGridView = cmb.EditingControlMyDataGridView

    ‘ Dim value As Object = cmb.Text

    ‘ ‘// Add value to list if not there

    ‘ If cmb.Items.IndexOf(value) = -1 Then

    ‘ ‘// Must add to both the current combobox as well as the template, to avoid duplicate entries…

    ‘ cmb.Items.Add(value)

    ‘ Dim cmbCol As MyDataGridViewComboBoxColumn = CType(grid.Columns(grid.CurrentCell.ColumnIndex), MyDataGridViewComboBoxColumn)

    ‘ If Not cmbCol Is Nothing Then

    ‘ cmbCol.Items.Add(value)

    ‘ End If

    ‘ grid.CurrentCell.Value = value

    ‘ End If

    ‘ End If

    ‘End If
End Sub

Public Class GenericListItem(Of T)
    Private mText As String
    Private mValue As T

    Public Sub New(ByVal pText As String, ByVal pValue As T)
        mText = pText
        mValue = pValue
    End Sub

    Public ReadOnly Property Text() As String
        Get
            Return mText
        End Get
    End Property

    Public ReadOnly Property Value() As T
        Get
            Return mValue
        End Get
    End Property

    Public Overrides Function ToString() As String
        Return mText
    End Function
End Class[/vb]

I hope this helps, and if you have any question let me know.

Happy coding 🙂

Share

Learn SharePoint 2010 without installations or top hardware

So you have decided you want to get into SharePoint, but you find out that you need to have a pretty strong machine to run it. Actually the latest SharePoint 2010 needs 6 GB of RAM as a starting point to run well and a 64 bit Windows 2008 operating system.

You could actually learn without installing a thing! Yes. Microsoft offers a great service called MSDN Virtual Labs.MSDN vlab Using these Virtual Labs you can test and try almost every Microsoft technology and product. And of course SharePoint Virtual Labs is one of them. In the Lab courses you get to learn and have hands-on experience. They even include software which you would need like SharePoint Designer. Really helpful.

So go on and have fun Smile

Share

Make Connectify work with Avast

Recently I updated Connectify to version 3.1 and it just stopped working.

After sometime of trial and error I found out that Avast Antivirus(I have Avast Internet Security) was blocking some essential ports which Avast uses.

Basically what needs to be done are two things:

  1. Enable the Internet Sharing mode in the Firewall settings

    Enable Sharing Mode

  2. Enable some Firewall packet rules for the application ConnectifyNetServices.exe

    Enable some Packet Rules

That’s set, your ready Smile go ahead and try it.

Share

Microsoft and Hadoop

Looks like Microsoft is going to start integrating Hadoop based services in its server and database products. The services will be implemented in Windows Server, Azure and SQL Server 2012.

Hadoop open source project which is if I may say for cloud and distributed computing came to the picture as I  remember when Yahoo announced that they will be using it to store their data. That was long time ago. Later I also learned that other companies which need to manage their big volume of data like Google actually uses it too.

The good thing is that according to Microsoft’s statement is that existing Microsoft Business Intelligence tools will be compatible with Hadoop implementation.

Microsoft’s Hadoop’s efforts already showing results like a Hadoop to SQL Server connector for importing and exporting and an ODBC driver for Hive for real time querying from business intelligence tools into Hadoop.

Microsoft promised that they will contribute back whatever changes or additions they make and will commit to make it compatible with the open source project.

I love SQL Server and I’m glad to see this move from Microsoft. Hopefully this will help better manage big data requirements.

Share

How to save on Mobile bills in Syria

Just wanted to share a few tips about reducing your mobile bill.

So far we got two Mobile providers in Syria which are almost identical. SyriaTel and MTN.

SMS

It is not just in Syria, but in a lot of countries Mobile companies still charges a lot for SMS despite how simple it is.

Lately I noticed that MTN and SyriaTel are offering good bundles to reduce the SMS cost.

So I advice all the people who uses SMS to pick one of the offers below. It will even reduce your mobile bill while using SMS instead of calling 🙂 I think the 100 SMS is sweet.

SyriaTel

Send SMS with the code to number 1220:

Messages Price Saving Code
25 SMS 50 SYP %67 ر 25
100 SMS 100 SYP %83 ر 100
3000 SMS 1500 SYP %92 ر 3000

MTN

To subscribe call *111# and choose package number:

Messages Price
25 SMS 50 SYP
100 SMS 100 SYP
Unlimited 1500 SYP

 

GPRS

While I still think that the GPRS cost is very high, the bundles are still a way to save some money if you need to use GPRS.

SyriaTel

Send SMS with the code to number 1221:

Messages Price Saving Code
3MB 50 SYP %33 ج 3
5MB 75 SYP %40 ج 5
12MB 150 SYP %50 ج 12
25MB 250 SYP %60 ج 25

MTN

To subscribe call *111# and choose package number:

Messages Price
3MB 50 SYP
5MB 75 SYP
12MB 150 SYP
25MB 250 SYP

 

Well that’s set for now, hope you like it 🙂

Share

Twitter Plugin for Windows Live Photo Gallery

Windows Live Essentials comes with lot of awesome applications.

My favorite is Windows Live Photo Gallery. Nice way of organizing and sharing your photos. Most favorite feature is facial recognition, which let you find photos by faces.

After adding photos it starts recognizing faces and ask you to tag the persons in the photos. After tagging people the application starts guessing the persons in the photos and asks if the guess was correct or not. And it gets better at it very fast.

So in the future, whenever you add new photos it will automatically tag people. I started adding really old photos, and I was surprised by its ability to guess that it’s me in a very old photo when I was about 3 years old! So smart!

Other great feature is how easy it is to share photos and videos. Out of the box you can submit your files to SkyDrive (Awesome free 25GB space from Microsoft), Flickr, Youtube and others. But I couldn’t find an option for Twitter!

That’s why I started making a Twitter plugin for Windows Live Photo Gallery. And I made it open source since I couldn’t find any open source plugin for the Windows Live Photo Gallery.

I used CodePlex to host the project and TortoiseHg for distributed revision control system.

Please note that this project is not complete yet. What is left for now is the integration with Windows Live Gallery.

What I’ve finished and is working now is uploading a photo to TwitPic and then post it to Twitter along with a message. What’s left is only using the Windows Live Gallery SDK to communicate with this little application.

The project is hosted here: http://twitter4wlpg.codeplex.com/

You are welcome if you would like to give a hand 🙂

Share