Wednesday, August 8, 2012

Safe thread in a listview. Getting the CheckListViewCollection

I am working with an application in .NET Framework 2.0. I am trying to work with a Safe-Thread method that will help me to get the checkitems in a listview. This is a reminder to my self. I had seen a lot of examples with textboxes, but few with listviews.

 First we need to create a delegate.
'Delegate for getting the CheckListItems
Private Delegate Function GetCheckListItems(lst As ListView) As ListView.CheckedListViewItemCollection

'this maybe in a button
Dim t As New Threading.Thread(AddressOf yourMethod)   
Private Sub YourMethod()    
'Something TODO....    
Dim x As String = GetValuesFromList()
Private Function GetValuesFromList() As String    
'there is not validation of any kind on this.    
'the purpose is just to use a safe-thread with a
' listview.CheckedListViewCollection
Dim mylist As New StringBuilder    
Dim lst As ListView.CheckedListViewItemCollection = getListViewItems(MyListView)    
For Each item As ListViewItem In lst
  mylist.Append(item.Tag.ToString & ",")    
Return mylist.ToString

'This is the safe call. We need to copy the items from one listview to another
' that way we avoided the cross-thead
' It is important set Checkboxes property to true. Without that the selected check items
' will not be copied to the temp variable.
Function Private Function getListViewItems(lstview As ListView) As ListView.CheckedListViewItemCollection    
 Dim temp As New ListView    
 temp.CheckBoxes = True    
If Not lstview.InvokeRequired Then        
 For Each item As ListViewItem In lstview.Items            
     temp.Items.Add(DirectCast(item.Clone(), ListViewItem))        
  Return CType(temp.CheckedItems, ListView.CheckedListViewItemCollection)    
 Return DirectCast(Me.Invoke(
   New GetCheckListItems(AddressOf getListViewItems), New Object() {lstview}),  
End If
End Function

Tuesday, August 7, 2012

Installing Ruby and Rails. First try..

I decided to use There is nothing especial in my choice than just a quick choice. After following the defaults in the installer and click in all the checkboxes in the following picture:
After that I installed also the development kit with all default options. Run the following commands
ruby dk.rb init
ruby dk.rb review
ruby dk. rb install
gem install rails --include-dependencies --no-rdoc --no-ri

Later I tried the command to create a new rails app in a new folder: rails new my_app.
However it fails because apparently I did not have some packages. So I did the following commands:

gem install rake -v ''
gem install coffee-script-source -v '1.3.3'
gem install execjs - v '1.4.0'
gem install coffe-script -v '2.2.0'
gem install json -v '1.7.4'
gem install rdoc -v '3.12'
gem install coffee-rails -v '3.2.2'
gem install jquery-rails -v '2.0.2'
gem install sass -v '3.1.20'
gem install sqlite3 -v '1.3.6'
gem install uglifier -v '1.2.7'

Then I tried again the command to create the app: rails new my_app.

This time it works.

I will post what will happen next.