0
votes

I need to fire an Event when Column value == "Discount" in GridView. I used Repository Lookup Edit in 1st Column. So if I choose any Item it perform some calculation. if i choose "Discount" particulat Item from Repository Lookup Edit, I need to fire another calculation. I tried this code but it skip if condition.

private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
{ 
    GridView view = sender as GridView; 
    if (gridView1.Columns["Type"] == gridView1.GetFocusedRowCellValue("Discount")) { 
        if (e.Column.FieldName == "Totalototal" && e.IsGetData)
           e.Value = getTotalValue(view, e.ListSourceRowIndex); 
    } 
}

How to write if condition ??

1
Where do you havce that code? ie which event handler method? - Chris L
Hi Chris, i used private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e) { GridView view = sender as GridView; if (gridView1.Columns["Type"] == gridView1.GetFocusedRowCellValue("Discount")) { if (e.Column.FieldName == "Totalototal" && e.IsGetData) e.Value = getTotalValue(view, e.ListSourceRowIndex); } } - Srihari
I Used CustomUnboundColumnData Event - Srihari
Can you edit your question to include the code in your comment please? - Bill Woodger
Hi Bill Woodger ` if (gridView1.Columns["Type"] == gridView1.GetFocusedRowCellValue("Discount")) { }` - Srihari

1 Answers

1
votes

Try this:

Suppose your RepositoryItemGridLookUpEdit is bound like this :

repositoryItemGridLookUpEdit1.DisplayMember = "Description";
repositoryItemGridLookUpEdit1.ValueMember = "Id";
// here probably you will use a table from db
repositoryItemGridLookUpEdit1.DataSource = new [] 
{
     new  { Id=1, Description = "Normal" },
     new  { Id=2, Description = "Discount" },
};

then you have your GridControl and set the DataSource like this :

class GridViewDataSource
{
    // the id of the description type
    public int DescriptionId { get; set; } 
}

// again, this probably is taken from db
gridControl2.DataSource = new GridViewDataSource[] 
{
       new GridViewDataSource {  DescriptionId = 1 },
       new GridViewDataSource {  DescriptionId = 2 },
       new GridViewDataSource {  DescriptionId = 1 },
       new GridViewDataSource {  DescriptionId = 2 },
};

Then you have to create CustomUnboundColumnData event

void gridView2_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
    {
        GridView view = sender as GridView;
        if (e.Column.Name == "UnboundColumn" && e.IsGetData)
        {
            // here you get the Id of the type
            var value = (int)view.GetListSourceRowCellValue(e.ListSourceRowIndex, TypeColumn);
            // here you get the "Description", for example "Normal" or "Discount"
            var text = repositoryItemGridLookUpEdit1.Properties.GetDisplayText(value);

            // here you can whatever you want, for example set the text of an unbound column to something
            if(text == "Discount")
                e.Value = "!!!!";
        }
    }

Your TypeColumn should have this properties:

this.TypeColumn.Caption = "TypeColumn";
this.TypeColumn.ColumnEdit = this.repositoryItemGridLookUpEdit1;
this.TypeColumn.FieldName = "DescriptionId";
this.TypeColumn.Name = "TypeColumn";

And you UnboundColumn these:

this.UnboundColumn.Caption = "UnboundColumn";
this.UnboundColumn.FieldName = "None";
this.UnboundColumn.Name = "UnboundColumn";
this.UnboundColumn.UnboundType = DevExpress.Data.UnboundColumnType.String;