Thursday, 28 November 2013

Setting AxGridView index in C# and in AX 2012


Setting AxGridView index in C# and in AX 2012
 
 
 
Sometimes we face issue with AxGridView to set the selected row as current. This may be due to number of reasons like if you are doing some task or operation in that process we are somehow running “executeQuery” of the data set.

 

Here is the small example to set the AxGridView index.

 

Step1: Add an AxGridview.

Step2: Add Data set and add fields

Step3: In the properties of AxGridView write an event “Selectedindexchanging”

onselectedindexchanging="SelectedRow_Changing"

Step4: write the below code in “SelectedRow_Changing” method.

protected void SelectedRow_Changing(object sender, GridViewSelectEventArgs e)

    {

        int i;

        i = e.NewSelectedIndex; // get the new selected index

        //Set new changed index as current row in data set.

        DataSetView dataSetView;

        dataSetView = this.MkTempSelectedDS.GetDataSet().DataSetViews["TmpFrmVirtual"];

        dataSetView.SetCurrent(i);

    }

 

 

Now we will see how we can also set through AX

 

Step1: Goto Data set, Data source execute method which you want to modify.

In my example \Data Sets\MkSalesListEntry\Data Sources\SalesLine\Methods\executeQuery

Step2: write the below code in executeQuery method

public void executeQuery()

{

    SalesLine       lSalesLine;

    lSalesLine  = SalesLine.data();

    super();

    Salesline_ds.findRecord(lSalesLine);

    Salesline_ds.setCurrent();

}

 

 

Happy Learning J

No comments:

Import and Export file from BLOB storage Account(Azure) in D365 F&O using X++

  Import and Export file from BLOB storage Account in D365 F&O using X++ Import: /// <summary> /// MKInventQualityOrderLineService...