The DataModel at the DB implements a Master-Slave architecture which is presented at the system with a WinForm with several controls for the MasterTable, and a Datagridview for the Slave one. All the controls for MasterTable fields' are binded through a BindingSource component, and the Datagridview for the SlaveTable uses its own BingindSource for the Fk constraint; by doing so, the user can navigate through the MasterTable's records via the MasterTable's Binding "position" in such a way that the main controls are update with the record's data, and the Datagridview is as well updated based on the MasterTable's Pk, thanks to the Fk constraint (implemented as a DataRelation and added to the MasterTable's DataSet and, for consequence, present at it's BindingSource).
Looking at the web and the forums (like here), I've found that the main controls could be binded programmatically with DataBinding.Add() if I wish to, i.e., give format to the text displayed at the Textboxes, as follows:
......
mainBind = new BindingSource();
slaveBind = new BindingSource();
mainBind.DataSource = mainDS;
mainBind.DataMember = "MasterTable";
slaveBind.DataSource = mainBind;
slaveBind.DataMember = "idFk"; //defined as DataRelation between Master-Slave tables
DataGrid.DataSource = slaveBind;
Text1.DataBindings.Add("Text", mainBind, "field1", true, DataSourceUpdateMode.OnPropertyChanged, 19, "$##.00");
Text2.DataBindings.Add("Text", mainBind, "field2", true, DataSourceUpdateMode.OnPropertyChanged, DateTime.Now, "dd/MM/yyyy");
.....
With this approach, the system works as intended.
Now, as far as I've understood, one cannot avoid to add each control programmatically to it's BindingSource if you are not willing to use, for example, a DataSource via the wizard (or the Entity Framework). Is this true?
By the other hand (which follows my real question here), by binding the Datagridview to the slaveBind and it's Fk's member, all the fields from the SlaveTable are actually loaded and displayed so, If I need to manipulated them (like make some columns not visible), I need to either modify the SELECT clause or programmatically modify each column (which include things like alignment or display format), as follows:
.....
DataGrid.Columns[0].Visible = false; //field1
DataGrid.Columns[1].Visible = false; //field2
DataGrid.Columns[2].Visible = false; //field3
DataGrid.Columns[3].Width = 184; //field4
DataGrid.Columns[3].DefaultCellStyle.Format = "N1";
.....
So, if I would like another approach like to add myself the columns to the Datagridview via the VS editor and then bind them, I need to remove the fk's binding source for it to work (if not, the automatic data load prevails); by consequence, I loose as well the possibility to keep tied the MasterTable's Pk to the data displayed at the Datagridview.
Is it a way to avoid to custom each Datagridview's column programmatically in this scenario?
Thanks a lot in advanced for anyone willing to support this issue.
p.s. I saw a video in YouTube not long time ago which implemented the Master-Slave architecture by cleaning and refilling the Datagridview each time the MasterTable records were traversed: is this the only solution around?