Home Forums WinForms controls Xceed Grid for WinForms ExtendedProperties

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #13459 |

    Why the ExtendedProperties aren’t support in the DataBoundColumn?

    How can I to memorize my custom info? My Grid1.Columns(Index).Tag it’s just full! 😉

    Thanks!

    Imported from legacy forums. Posted by AndreaZ (had 675 views)

    User (Old forums)
    Member
    Post count: 23064

    The <b>ExtendedProperties</b> property of a System.Data.DataColumn is just an object of type <b>System.Data.PropertyCollection</b>, which is just a Hashtable.

    So you can just put a Hashtable in the Tag property of the Xceed.Grid.Column (or any GridElement). Here’s a class that helps using the Tag property as ExtendedProperties (warning: untested code):<code>
    using System;
    using System.Collections;
    using Xceed.Grid;
    public class ExtendedProperties
    {
    public static Hashtable Get(GridElement element)
    {
    Hashtable h = element.Tag as Hashtable;
    if (h == null)
    {
    h = new Hashtable();
    element.Tag = h;
    }
    return h;
    }

    public static object Get(GridElement element, object key)
    {
    return Get(element)[key];
    }

    public static void Set(GridElement element, object key, object value)
    {
    Get(element)[key] = value;
    }
    }</code>You can use it like this:<code>object prop = ExtendedProperties.Get(Grid1.Columns[Index], “key”);
    ExtendedProperties.Set(Grid1.Columns[Index], “key”, “newvalue”);
    Hashtable allProperties = ExtendedProperties.Get(Grid1.Columns[Index]);</code>

    Imported from legacy forums. Posted by Tommy (had 153 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks, I will try!

    Imported from legacy forums. Posted by AndreaZ (had 233 views)

    User (Old forums)
    Member
    Post count: 23064

    Great!

    So this one works for all objects. Is it right?
    Imports System
    Imports System.Collections

    Public Class myExtendedProperties

    Public Shared Function GetValue(ByVal element As Object) As Hashtable

    ‘the Tag MUST BE empty!
    Dim h As Hashtable = element.Tag
    If h Is Nothing Then
    h = New Hashtable
    element.Tag = h
    End If
    Return h

    End Function

    Public Shared Function GetValue(ByVal element As Object, ByVal key As String) As Object

    Return GetValue(element)(key)

    End Function

    Public Shared Sub SetValue(ByVal element As Object, ByVal key As String, ByVal value As Object)

    GetValue(element)(key) = value ‘allow NullValues

    End Sub

    End Class

    ================================================

    ‘set TextBox1 extended properties
    myExtendedProperties.SetValue(TextBox1, “ID”, 55)
    myExtendedProperties.SetValue(TextBox1, “Nome”, “TextBox1”)
    myExtendedProperties.SetValue(TextBox1, “Tipo”, “Casella di testo”)

    ================================================

    ‘read TextBox1 extended properties
    TextBox2.Text = “ID: ” & myExtendedProperties.GetValue(TextBox1, “ID”).ToString & vbCrLf
    TextBox2.Text &= “Nome: ” & myExtendedProperties.GetValue(TextBox1, “Nome”).ToString & vbCrLf
    TextBox2.Text &= “Tipo: ” & myExtendedProperties.GetValue(TextBox1, “Tipo”).ToString & vbCrLf

    Imported from legacy forums. Posted by AndreaZ (had 281 views)

    User (Old forums)
    Member
    Post count: 23064

    Well, no.
    element should be of type Xceed.Grid.GridElement and not Object. GridElement has a Tag property, Object doesn’t. System.Windows.Forms.Control also has a Tag property, so you could support both GridElement and Control, like this:<code>Imports System
    Imports System.Collections
    Imports System.Windows.Forms
    Imports Xceed.Grid

    Public Class myExtendedProperties
    Public Shared Function GetValue(ByVal element As GridElement) As Hashtable
    Dim h As Hashtable = element.Tag
    If h Is Nothing Then
    ‘ if the Tag is empty, create it
    h = New Hashtable
    element.Tag = h
    End If
    Return h
    End Function

    Public Shared Function GetValue(ByVal element As Control) As Hashtable
    Dim h As Hashtable = element.Tag
    If h Is Nothing Then
    ‘ if the Tag is empty, create it
    h = New Hashtable
    element.Tag = h
    End If
    Return h
    End Function

    Public Shared Function GetValue(ByVal element As GridElement, ByVal key As String) As Object
    Return GetValue(element)(key)
    End Function

    Public Shared Function GetValue(ByVal element As Control, ByVal key As String) As Object
    Return GetValue(element)(key)
    End Function

    Public Shared Sub SetValue(ByVal element As GridElement, ByVal key As String, ByVal value As Object)
    GetValue(element)(key) = value
    End Sub

    Public Shared Sub SetValue(ByVal element As Control, ByVal key As String, ByVal value As Object)
    GetValue(element)(key) = value
    End Sub
    End Class</code>

    Imported from legacy forums. Posted by Tommy (had 145 views)

    User (Old forums)
    Member
    Post count: 23064

    GREAT!

    Thanks!!!

    Imported from legacy forums. Posted by AndreaZ (had 5214 views)

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.