Unsure if this is what you are after. I setup a ComboBox DataSource to RootMachineProfile
as a list. This means you have access to each property that can be data bound to controls. Classes were generated by Visual Studio paste special.
For the ComboBox, no need to set DisplayMember.
public class XmlOperations
{
public static Root Read()
{
const string fileName = @"XMLFile1.xml";
var xmlSerializer = new XmlSerializer(typeof(Root), new XmlRootAttribute { ElementName = "Root", IsNullable = true });
using (var fs = new FileStream(fileName, FileMode.Open))
{
return (Root)xmlSerializer.Deserialize(fs);
}
}
}
[SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[XmlTypeAttribute(AnonymousType = true)]
[XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class Root
{
private RootCompanyProfile companyProfileField;
private RootMachineProfile[] machineProfileField;
public RootCompanyProfile CompanyProfile
{
get => companyProfileField;
set => companyProfileField = value;
}
[XmlElementAttribute("MachineProfile")]
public RootMachineProfile[] MachineProfile
{
get => machineProfileField;
set => machineProfileField = value;
}
public override string ToString() => $"{CompanyProfile.CompanyName}";
}
/// <remarks/>
[SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[XmlTypeAttribute(AnonymousType = true)]
public partial class RootCompanyProfile
{
private string companyNameField;
private string siteNameField;
private uint imoField;
private int machineTotalField;
public string CompanyName
{
get => companyNameField;
set => companyNameField = value;
}
public string SiteName
{
get => siteNameField;
set => siteNameField = value;
}
public uint Imo
{
get => imoField;
set => imoField = value;
}
public int MachineTotal
{
get => machineTotalField;
set => machineTotalField = value;
}
}
[SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[XmlTypeAttribute(AnonymousType = true)]
public partial class RootMachineProfile
{
private string machineNameField;
private uint serialNumberField;
private string typeNumberField;
private string typeField;
private ushort nominalSpeedField;
private byte frequencyField;
private ushort nominalPowerField;
public string MachineName
{
get => machineNameField;
set => machineNameField = value;
}
public uint SerialNumber
{
get => serialNumberField;
set => serialNumberField = value;
}
public string TypeNumber
{
get => typeNumberField;
set => typeNumberField = value;
}
public string Type
{
get => typeField;
set => typeField = value;
}
public ushort NominalSpeed
{
get => nominalSpeedField;
set => nominalSpeedField = value;
}
public byte Frequency
{
get => frequencyField;
set => frequencyField = value;
}
public ushort NominalPower
{
get => nominalPowerField;
set => nominalPowerField = value;
}
public override string ToString() => MachineName;
}
Form code
var result = XmlOperations.Read();
List<RootMachineProfile> dataSource = result.MachineProfile.ToList();
comboBox1.DataSource = dataSource;