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:

Update NuGet package to new MS D365FO version

1. Import the NuGet package files from LCS for that particular version please take the PU version files only. a. Goto LCS-->Asset Libra...