Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1660
Wingrid with dropdown having different datasource
posted

Hi,

We have a wingrid with 2 level bands. Level 0 - parent, Level 1 - Child. Child has 2 columns. Based on the column 1 the column 2 dropdown should be loaded. Earlier we have done this in web based. Here we are not able to use the javascript function. Need help on which event will have the row datakeyfield and how to load the datasource to the dropdown. Sample coding as follows.

Loading Grid:

DataSet dsMenus = new DataSet();
DBHelper.DLConnect dl = new DLConnect();
try
{
string sSQL = "Query ";
dsMenus = dl.ExecuteDataSet(sSQL);
DataRelation relChildClass1 = new DataRelation("MenuLevel1", dsMenus.Tables[0].Columns[MENU_KEY], dsMenus.Tables[1].Columns[MENU_PARENT_KEY]);
dsMenus.Relations.Add(relChildClass1);
roles_Grid.DataSource = dsMenus;
roles_Grid.Rows.CollapseAllCards();
roles_Grid.DisplayLayout.AutoFitStyle = Infragistics.Win.UltraWinGrid.AutoFitStyle.ResizeAllColumns;
}

Initialize Row:

e.Layout.Bands[0].Columns[MENU_KEY].Hidden = true;
e.Layout.Bands[1].Columns[ROLE_MENU_KEY].Hidden = true;
e.Layout.Bands[1].Columns[CREATED_BY].Hidden = true;
e.Layout.Bands[1].Columns[CREATED_DATE].Hidden = true;
e.Layout.Bands[1].Columns[LAST_MODIFIED_BY].Hidden = true;
e.Layout.Bands[1].Columns[LAST_MODIFIED_DATE].Hidden = true;
e.Layout.Bands[0].Columns[MENU_NAME].CellActivation = Infragistics.Win.UltraWinGrid.Activation.NoEdit;
e.Layout.Bands[0].Columns[MENU_NAME].Header.Caption = "Module";
e.Layout.Bands[1].Columns[MENU_KEY].Hidden = true;
e.Layout.Bands[1].Columns[MENU_PARENT_KEY].Hidden = true;
e.Layout.Bands[1].Columns[MENU_NAME].CellActivation = Infragistics.Win.UltraWinGrid.Activation.NoEdit;
e.Layout.Bands[1].Columns[MENU_NAME].Header.Caption = "Sub Module";
e.Layout.Bands[1].Columns[ACCESS_TYPE_KEY].CellActivation = Infragistics.Win.UltraWinGrid.Activation.AllowEdit;
e.Layout.Bands[1].Columns[ACCESS_TYPE_KEY].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
e.Layout.Bands[1].Columns[ACCESS_TYPE_KEY].Band.Columns.Cast();
e.Layout.Bands[1].Columns[ACCESS_TYPE_KEY].Header.Caption = "Access Type";
e.Layout.AutoFitStyle = AutoFitStyle.ResizeAllColumns;
//e.Layout.Bands[0].ColHeadersVisible = true;
//e.Layout.Bands[1].ColHeadersVisible = true;


Parents
  • 21795
    Verified Answer
    Offline posted

    Hello Thangachan,

    Thank you for posting in our forum.

    If I understand you correctly you have hierarchical grid, for which you need to add conditionally drop downs to the cells in a particular column in the second band. You can achieve this by handling InitializeRow event of the grid. In this event you can check if the row is in the child band. if so check the value of the cell on which the dropdown values depends. Created the dropdown depending on the cell value and add it to the cell where the dropdown should appear. You may use code like this:

    private void UltraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)

    {

        // if the row reinitialize just exit the event as dropdowns should be already set

        if (e.ReInitialize)

        {

            return;

        }

     

        // if the band index is 1 this is the child band so set the dropdowns

        if (e.Row.Band.Index == 1)

        {

            // get a reference to the cell in current row where the dropdown will be added

            var dropdownCell = e.Row.Cells["Name"];

     

            // set the style of the cell

            dropdownCell.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;

     

            // create a VlueList which later will be populated with values according to firs cell value

            var vl = new ValueList();

     

            // set the ValueList as drop down cell value list

            dropdownCell.ValueList = vl;

     

            // depending on the value in first cell add different items to drop down

            switch (e.Row.Cells["id"].Text)

            {

                case "0":

                    vl.ValueListItems.Add("Microsoft");

                    vl.ValueListItems.Add("Lumia");

                    vl.ValueListItems.Add("Surface");

                    break;

                case "1":

                    vl.ValueListItems.Add("Apple");

                    vl.ValueListItems.Add("iPhone");

                    vl.ValueListItems.Add("iPad");

                    break;

                case "2":

                    vl.ValueListItems.Add("Samsung");

                    vl.ValueListItems.Add("Galaxy");

                    vl.ValueListItems.Add("Galaxy Tab");

                    break;

            }

        }

    }

    Please check the attached sample project where I have implement this approach and let me know if you need any additional information.

    CAS-171448-W6C6T6.zip
Reply Children
No Data