Tutorials‎ > ‎

C# Tutorials


How do I declare an image property in the ORM Data Model Designer

posted Feb 15, 2016, 9:36 AM by Tim Key

See step by step solution at DevExpress.com

ObjectClassInfo of XPCollection component does not show available XPO objects from referenced assembly

posted Feb 15, 2016, 7:51 AM by Tim Key

I have a WinForm on which I drag an XPCollection component. A separate Class Library project contains all my XPO objects. This class library is referenced by the WinForm application.

The ObjectClassInfo of the XPCollection component allows me to choose which type of object the collection contains. The dropdown in the property editor does not list my XPO objects from the class library. How can I make them available in the dropdown?


Solution

The XPCollection lists classes from the compiled project. You should use any class of your referenced assembly in your project, e.g. declare a variable of your persistent object, and rebuild your project. Then reopen the form designer with your XPCollection component. Now you can select persistent classes declared in your assembly for the ObjectClassInfo property via the Property Window.

DevExpress XPO Data Model Image Field

posted Feb 15, 2016, 6:46 AM by Tim Key

I am using the Data Model Xpo Data Model Designer, I need to store images in the Database, what is the field type for this case?

Solution

To accomplish this task, create a property of the ByteArray type and apply the [DevExpress.Xpo.ValueConverter(typeof(DevExpress.Xpo.Metadata.ImageValueConverter))] attribute to it via the designer's Custom Attributes property.

See Also:
ImageValueConverter Class


Original Source

Trap Enter Key

posted Mar 28, 2012, 9:00 AM by Tim Key

        private void txtTextbox_KeyPress(object sender, EventArgs e)
        {
            //Trap the enter key
            string info = e.KeyChar.ToString();
            if (info == "\r")
            {
                //Your code here

                //This signals the event that you have managed the outcome
                e.Handled = true;
            }
        }

Common Mask for DevExpress TextEdit Control

posted Nov 30, 2011, 9:38 AM by Tim Key

Simple Mask Type:
    Phone - (999) 000-0000

RegEx Mask Type:
    Email - [a-zA-Z0-9.-]+@[a-zA-Z0-9-]+\.[A-Za-z]{2,}

How to use CSLA NameList

posted Sep 27, 2011, 6:37 AM by Tim Key   [ updated Sep 27, 2011, 6:40 AM ]

using System;
using Csla;
using System.Data.SqlClient;
using System.Data;
using Csla.Data;
 
namespace CSLASample.NameList
{
    [Serializable]
    public class FindItemCollection : NameValueListBase<stringstring>
    {
        #region Factory Methods
 
        private static FindItemCollection _list;
 
        public static FindItemCollection GetFindItemCollection()
        {
            if (_list == null)
                _list = DataPortal.Fetch<FindItemCollection>();
            return _list;
        }
 
        public static void InvalidateCache()
        {
            _list = null;
        }
 
        private FindItemCollection()
        { /* require use of factory methods */ }
 
        #endregion
 
        #region Data Access
 
        private void DataPortal_Fetch()
        {
            RaiseListChangedEvents = false;
            IsReadOnly = false;
            //Load Values
            using (SqlConnection cn = new SqlConnection(Database.Connection))
            {
                cn.Open();
                using (SqlCommand cm = cn.CreateCommand())
                {
                    cm.CommandType = CommandType.StoredProcedure;
                    cm.CommandText = "getFindItemList";
                    using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
                    {
                        while (dr.Read())
                        {
                            Add(new NameValueListBase<stringstring>.NameValuePair(
                                dr.GetString("IMA_ItemID"), dr.GetString("IMA_ItemName")));
                        }
                    }
                }
            }
            IsReadOnly = true;
            RaiseListChangedEvents = true;
        }
 
        #endregion
    }
}

Restrict textbox to numeric only

posted Nov 23, 2010, 7:32 AM by Tim Key   [ updated Nov 26, 2010, 6:21 AM ]

Instructions:  Place the code below into a KeyPress event for the textbox you wish to restrict


Code Snippet:

//The first "if" statement is for numeric only.  The second section "else if" allows one decimal place.

//You may leave off the "else if" if you do not wish to allow a decimal.

if (char.IsNumber(e.KeyChar) || char.IsControl(e.KeyChar))
{
    //Allow
}
else if (e.KeyChar == Convert.ToChar(".") && textbox1.Text.IndexOf(".") == -1)
{
    //Allow
}
else
{
    e.Handled = true;
}

1-7 of 7