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
500
adding new rows to a multiband grid
posted

Hello and greetings from germany

I am trying a little bit with Infragistics cause i should getting a project started by end of the week

and i am a little bit helpless by the many features of the ultragrid.

Ok, i got a multiband grid with 3 depending grids

questions => answers => related data

Now i can insert new answers or edit existing answers.

In the answers band i got a ultratexteditor column with a dropdown treeview. The treeview inherits the related data band to this answer.

On closing of the dropdown treeview i wanted to add and change the "related data" band in relation to the answer. By adding new rows with

"ultraGrid1.ActiveRow.ChildBands[0].Band.AddNew()"

This works with answers which are already saved in the database. But when i added a new answer and wanted to add the "relating data" rows to it. The i got a foreignkey exception on the id column.

Another problem is how i can delete existing "related data" rows from a answer...

I a little bit overwhelmed of the many features and i hope there is someone who can help me.

 

Greetings from germany

 

Dietrich

 

SourceCode:

private void ultraTextEditor1_AfterEditorButtonCloseUp(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
        {
            int fall = 0;
            foreach (Infragistics.Win.UltraWinTree.UltraTreeNode node in ultraTree1.Nodes)
            {
                if (node.Text.Equals("Applications"))
                    fall = APPLICATION_NODE;
               
                if (node.Text.Equals("Components"))
                    fall = COMPONENT_NODE;
               
                foreach (Infragistics.Win.UltraWinTree.UltraTreeNode childNode in node.Nodes)
                {
                    handleNodes(childNode, fall);
                }
                ultraGrid1.UpdateData();
                DataTable dt = processQuestionsDataSet.MMProcess_AnswersValidForAppComp.GetChanges();
                //mmProcess_AnswersTableAdapter1.Update(processQuestionsDataSet.MMProcess_Answers);
                //mmProcess_AnswersValidForAppCompTableAdapter1.Update(processQuestionsDataSet.MMProcess_AnswersValidForAppComp);
            }
        }


        private static int APPLICATION_NODE = 1;
        private static int COMPONENT_NODE = 2;
        private void handleNodes(Infragistics.Win.UltraWinTree.UltraTreeNode node,int fall)
        {
            processQuestionsDataSet.rel_suchenProcessQuestionApplicationsRow rowApp = null;
            processQuestionsDataSet.rel_suchenProcessQuestionComponentsRow rowComp = null;
            int idAppComp = 0;
            if (fall == APPLICATION_NODE)
            {
                rowApp = (processQuestionsDataSet.rel_suchenProcessQuestionApplicationsRow)node.Tag;
                idAppComp = rowApp.ValidApps;
            }
            if (fall == COMPONENT_NODE)
            {
                rowComp = (processQuestionsDataSet.rel_suchenProcessQuestionComponentsRow)node.Tag;
                idAppComp = rowComp.ValidComp;
            }

            if (node.CheckedState == CheckState.Checked)
            {
                Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
                if (idAppComp == 0)
                {
                    try
                    {
                        row = ultraGrid1.ActiveRow.ChildBands[0].Band.AddNew();
                    }
                    catch (Exception ex)
                    {
                        row = ultraGrid1.ActiveRow.Band.AddNew();
                    }
                    processQuestionsDataSet.MMProcess_AnswersValidForAppCompRow appcompRow = (processQuestionsDataSet.MMProcess_AnswersValidForAppCompRow)((DataRowView)row.ListObject).Row;
                    if (fall == APPLICATION_NODE)
                    {
                        appcompRow.ApplicationID = int.Parse(node.Key.ToString());
                        rowApp.ValidApps = appcompRow.ID;
                    }
                    if (fall == COMPONENT_NODE)
                    {
                        appcompRow.ComponentID = int.Parse(node.Key.ToString());
                        rowComp.ValidComp = appcompRow.ID;
                    }
                    appcompRow.MMProcessAnswersID = activeAnswer;
                   
                    ultraGrid1.UpdateData();
                }
            }
            if (node.CheckedState == CheckState.Unchecked)
            {
                processQuestionsDataSet.MMProcess_AnswersValidForAppCompDataTable dt;
                if (idAppComp != 0)
                {
                    dt = processQuestionsDataSet.MMProcess_AnswersValidForAppComp;
                    DataRow dr = null;
                    foreach (DataRow appcompRow in dt.Rows)
                    {
                        if (int.Parse(appcompRow[0].ToString()) == idAppComp)
                            dr = appcompRow;
                    }
                    if (dr!=null)
                        dt.Rows.Remove(dr);
                    mmProcess_AnswersValidForAppCompTableAdapter1.Update(processQuestionsDataSet.MMProcess_AnswersValidForAppComp);
                }

            }
        }