Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Monday, October 20, 2014

Cannot Add Reference To CrystalDecisions DLLS On VS 2010

Cannot add reference to CrystalDecisions.Shared, CrystalDecisions.ReportSource, CrystalDecisions.CrystalReports.Engine on VS 2010
I recently came across this situation where I had to print a report using crystal and VS2010
I had designed the report using Crystal Reports Designer. My task was to print the report on the click of the print button on my Win Form application.
First of all,Crystal doesn’t ship with VS 2010, you need to download and install this free exe from SAP Business Objects website
In the correct scenario , one can add the reference to to CrystalDecisions.Shared , CrystalDecisions.ReportSource, CrystalDecisions.CrystalReports.Engine using  Add Reference -> .NET tab .
However in my case I wasn’t seeing these dlls .
I tried adding them manually using browse and navigating to C:\Program Files\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjectsEnterpriseXI 4.0\win32_x86\dotnet
But I was tsill getting the reference error. After googling for some time I stumbled on the following page :
And following the discussion, I clicked on my Project Properties and Changed my target platform to .NET Framework 4 from .NET Framework 4 Client Profile.

Copied From: http://lazytechtips.wordpress.com/2011/07/15/cannot-add-reference-to-crystaldecisions-dlls-on-vs-2010/

Wednesday, April 2, 2014

Enter Only Numbers in Textbox in c#

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (!char.IsControl(e.KeyChar) 
        && !char.IsDigit(e.KeyChar) 
        && e.KeyChar != '.')
    {
        e.Handled = true;
    }

    // only allow one decimal point
    if (e.KeyChar == '.' 
        && (sender as TextBox).Text.IndexOf('.') > -1)
    {
        e.Handled = true;
    }
}

Monday, March 31, 2014

Binding Enum into DropDownList C#

public static class Enumeration
{
    public static IDictionary<int, string> GetAll<TEnum>() where TEnum: struct
    {
        var enumerationType = typeof (TEnum);

        if (!enumerationType.IsEnum)
            throw new ArgumentException("Enumeration type is expected.");

        var dictionary = new Dictionary<int, string>();

        foreach (int value in Enum.GetValues(enumerationType))
        {
            var name = Enum.GetName(enumerationType, value);
            dictionary.Add(value, name);
        }

        return dictionary;
    }
}
Bind To a DropDown:
ddlResponse.DataSource = Enumeration.GetAll<Response>();
ddlResponse.DataTextField = "Value";
ddlResponse.DataValueField = "Key";
ddlResponse.DataBind();