Here you are, study. Master finally the data binding.
using System.Data; using System.Linq; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { //InitializeComponent(); Width = 500; var dataSet = new DataSet(); dataSet.ReadXml("test.xml"); var bindingSource = new BindingSource(); bindingSource.DataSource = dataSet; var dataGridView = new DataGridView { Parent = this, Dock = DockStyle.Top }; dataGridView.DataSource = bindingSource; var editButton = new Button { Parent = this, Top = 200, Left = 200, Text = "Edit", Enabled = false }; editButton.Click += (s, e) => { var editForm = new EditForm(bindingSource); editForm.ShowDialog(); bindingSource.ResetCurrentItem(); }; var tablesComboBox = new ComboBox { Parent = this, Top = 200 }; tablesComboBox.DataSource = dataSet.Tables.OfType<DataTable>().Select(dt => dt.TableName).ToList(); tablesComboBox.SelectedIndexChanged += (s, e) => { string tableName = tablesComboBox.SelectedItem.ToString(); bindingSource.DataMember = tableName; editButton.Enabled = dataSet.Tables[tableName].Columns.Count != 1; }; } } public class EditForm : Form { public EditForm(BindingSource bindingSource) { var tableLayoutPanel = new TableLayoutPanel { Parent = this, Dock = DockStyle.Top, ColumnCount = 2, AutoSize = true }; var okButton = new Button { Parent = this, Text = "OK", DialogResult = DialogResult.OK, Left = 200, Top = 220 }; var dataSet = (DataSet)bindingSource.DataSource; foreach (DataColumn column in dataSet.Tables[bindingSource.DataMember].Columns) { if (!column.ColumnName.EndsWith("_Id")) { var label = new Label { Parent = tableLayoutPanel, Text = column.ColumnName }; var textBox = new TextBox { Parent = tableLayoutPanel, Top = 200, Left = 150 }; textBox.DataBindings.Add("Text", bindingSource, column.ColumnName); } } } } }
As data uses xml of the form:
<root> <config> <monitor price="1000" width="1280" height="768" /> <monitor price="1500" width="1440" height="800" /> <monitor price="2000" width="1600" height="900" /> <other price="20" feature="2" /> <other price="30" feature="3" /> </config> </root>
The number of nodes and attributes is arbitrary, as well as their names.