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); } } }
The error is not caused by the grid, but by your data source. Instead of adding rows to the grid, add them to the data source. You can get the DataRow of a grid row by row.ListObject.
Thanks a lot,...
My problem so far are mighty infragistics controls and that i'm realy not well into datasets, binding,...
Your quick answer saved my day.
Regards
MTC SindelfingenGermany
Using DataSets is the standard in my project team an so i have not much of a choice when developing projects in teams.
But it's getting better and better. When i further can get someone who can help me in special issues,... (thx a lot)
But i think that i would have a deeper look in linq when i have to exchange C1 controls to infragistics controls in my one-man project,... :-) if there is time and the code doesn't have be thrown together.
If your project is just starting, why use DataSet and DataTables, especially if you are not good with them? Consider using EntityFramework or Linq to Sql (I use the latter).