I have a form showing data from a database table (top level in the databse). This is the "case" table. The primary keys in this table, are "CaseYear" and "CaseNumber". These data are shown in textboxes on the form: "txtCaseYear" and "txtCaseNumber".
On the form I have a ultragrid showing data from a related table (with "child" records) which are multiple samples belonging to this particular case. In this table (and the ultragrid) column 1 and 2 is the foreign keys of the "sample" table.: "CaseYear" and "CaseNumber". How can I populate the cells in these columns with "default" values based on the textboxes "txtCaseYear" and "txtCaseNumber" on the mother form when new grid rows are added?
I dont want the user having to enter this manually as it is obvious that the samples belongs to the case currently viewed in the mother form. In fact, I would keep both these grid columns hidden in the grid.
Regards,
Kai
Hi Kai,
Thank you for posting in our forums.
You can hide the columns by setting their Hidden property to “true”. To do that subscribe to the InitializeLayout event and use this code:
private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
{
e.Layout.Bands[0].Columns["CaseNumber"].Hidden = true;
e.Layout.Bands[0].Columns["CaseYear"].Hidden = true;
}
For more information on this property, please visit this link:
http://help.infragistics.com/Help/Doc/WinForms/2011.2/CLR2.0/html/Infragistics2.Win.UltraWinGrid.v11.2~Infragistics.Win.UltraWinGrid.UltraGridColumn~Hidden.html.
Please let me know if you have any additional questions.
Thanks,
I am able to hide the columns already. My problem is to automatically fill cells in new rows with values found on the hosting form.
Thank you for the reply.
You can use the InitializeRow event to populate the rows with default values (you may need to do some conversions based on the column’s datatype):
void ultraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
if (e.Row.Band.Index == 0)
e.Row.Cells["CaseNumber"].Value = txtCaseNumber.Text;
e.Row.Cells["CaseYear"].Value = txtCaseYear.Text;
I have not have time to try yet. Will give feedback when I have.
Let me know if this solution fulfils your requirement when you are able to test it. Also do not hesitate to ask any additional questions you may have.
Thank you for using Infragistics components.