Click here to Skip to main content
15,921,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
dear all ,

i am trying to develop custom datagridview with custom column , now i has amountDatagrid
ViewColumn to deal with amount formatted with currency my problem is, i have a CurrencyId property which i want to get its value from the datagrid view datasource , as all of us know when you set DataPropertyName = "Column Name in dataset" the value of each set are bonded to the mapped datasource cell , i want to do the same i want the currencyId to get its value from the datasource

any idea to do that ?


this is my trying code :

this in control

C#
[Description("Gets or set the Currency value the cell can accept"), DefaultValue(null), Category("Data")]
        [BrowsableAttribute(true)]
        [TypeConverterAttribute("System.Windows.Forms.Design.DataMemberFieldConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
        public string CurrencyPropertyData { get; set; }



public int CurrencyID{get;set;}



using of the control :

C#
//
           // Column1
           //
           this.Column1.AllowNegative = false;
           this.Column1.CurrencyID = 0;
           this.Column1.DataPropertyName = "Amount";
           Column1.CurrencyPropertyData = "CurrencyId";
           this.Column1.HeaderText = "Column1";
           this.Column1.Mask = IBS.IBSControls.Enums.InputMask.None;
           this.Column1.MaxLength = 1000;
           this.Column1.MaxValue = new decimal(new int[] {
           0,
           0,
           0,
           0});
           this.Column1.MinValue = new decimal(new int[] {
           0,
           0,
           0,
           0});
           this.Column1.Name = "Column1";
           this.Column1.UseItemCurrency = false;



thanks in advanced
Posted
Comments
Sinisa Hajnal 18-May-15 6:29am    
You shouldn't bind one column to two values. CurrencyId should be dropdown column next to the amount. aMount should be simple decimal.

Assuming you want to continue with this, create currency enum with text you want to show either as enum names (i.e. USD, EUR, etc) or add description attribute to each (i.e. <description("us dollars")="">

Then in CellFormatting event do e.value = getWantedText(e.Value) where e.Value is integer you get from the database (I assume Id is an integer) and getWantedText gets the value you want to show from the enum (might be as simple as ((Enum)e.Value).ToString

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900