none
convert c# in vb.net - Collection base RRS feed

  • Question

  • Hi 

    I'm traying to convert c#code to vb.net taking code from Outolookgrid from codeproject, to group datagridviw rows

    I'm trying to understand how the solution works in order to modify it to my wish.

    The solution is in C# and I work with Vb.Net so I converted everything but not the following code I do not undersand

    #region DataSourceRow - abstract representation of a data item.
        /// <summary>
        /// The DataSourceRow is a wrapper row class around the real bound data. This row is an abstraction
        /// so different types of data can be encaptulated in this class, although for the OutlookGrid it will
        /// simply look as one type of data. 
        /// Note: this class does not implement all row wrappers optimally. It is merely used for demonstration purposes
        /// </summary>
        internal class DataSourceRow : CollectionBase
        {
            DataSourceManager manager;
            object boundItem;
            public DataSourceRow(DataSourceManager manager, object boundItem)
            {
                this.manager = manager;
                this.boundItem = boundItem;
            }
    
            public object this[int index]
            {
                get
                {
                    return List[index];
                }
            }
    
            public object BoundItem
            {
                get
                {
                    return boundItem;
                }
            }
    
            public int Add(object val)
            {
                return List.Add(val);
            }
    
        }
        #endregion DataSourceRow - abstract representation of a data item.

    The automatic conversion gives me the following :

    Friend Class DataSourceRow
            Inherits CollectionBase
    
            Private manager As DataSourceManager
            Private boundItem As Object
    
            Public Sub New(ByVal manager As DataSourceManager, ByVal boundItem As Object)
                Me.manager = manager
                Me.boundItem = boundItem
            End Sub
    
            Default Public ReadOnly Property Item(ByVal index As Integer) As Object
                Get
                    Return List(index)
                End Get
            End Property
    
            Public ReadOnly Property BoundItem As Object
                Get
                    Return boundItem
                End Get
            End Property
    
            Public Function Add(ByVal val As Object) As Integer
                Return List.Add(val)
            End Function
        End Class

    What I do not understand is the following block

    Default Public ReadOnly Property Item(ByVal index As Integer) As Object
                Get
                    Return List(index)
                End Get
            End Property

    What does it means ?

    Can somebody help me ?


    Thursday, July 26, 2018 3:15 PM

Answers

  • It allows you to access an item from the underlying collection by index.

    So if you had an instance of this class like:

    Dim dsr As New DataSourceRow

    and it was somehow filled with items, you could access an item by index like:

    Dim anItem = dsr(0)

    or 

    Dim anItem = dsr.Item(0)


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by Alex Li-MSFT Friday, July 27, 2018 5:37 AM
    • Unmarked as answer by Alex Li-MSFT Friday, July 27, 2018 5:37 AM
    • Proposed as answer by Alex Li-MSFT Friday, July 27, 2018 5:37 AM
    • Marked as answer by Claudio111 Friday, July 27, 2018 7:01 AM
    Thursday, July 26, 2018 6:20 PM
    Moderator

All replies

  • It allows you to access an item from the underlying collection by index.

    So if you had an instance of this class like:

    Dim dsr As New DataSourceRow

    and it was somehow filled with items, you could access an item by index like:

    Dim anItem = dsr(0)

    or 

    Dim anItem = dsr.Item(0)


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by Alex Li-MSFT Friday, July 27, 2018 5:37 AM
    • Unmarked as answer by Alex Li-MSFT Friday, July 27, 2018 5:37 AM
    • Proposed as answer by Alex Li-MSFT Friday, July 27, 2018 5:37 AM
    • Marked as answer by Claudio111 Friday, July 27, 2018 7:01 AM
    Thursday, July 26, 2018 6:20 PM
    Moderator
  • Reed gave you an explanation for the indexer.

    Also, you'll find that you have to rename the private 'boundItem' field - VB doesn't allow members with the same name (since VB is case-insensitive, it regards 'boundItem' and 'BoundItem' as the same name).


    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

    • Marked as answer by Claudio111 Friday, July 27, 2018 7:01 AM
    • Unmarked as answer by Claudio111 Friday, July 27, 2018 7:01 AM
    Thursday, July 26, 2018 7:57 PM
  • Good catch Dave.  The converter used should have placed an underscore before the field name, per convention.

    So _BoundItem should be the field and BoundItem should be the property.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


    Friday, July 27, 2018 2:25 AM
    Moderator
  • @ Dave

    I renamed the private field with _.

    Thank You

    Friday, July 27, 2018 7:02 AM