Here is the code that I came up with I decided to abandon xml and use a txt file instead as the data that I needed to store was not multidimensional.
.xaml
---------------------------------------------------
<window x:class="WpfApplication3.MainWindow" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<grid>
<stackpanel>
<combobox x:name="tbHostname" width="120" iseditable="True" />
<button x:name="btDisableSC" content=" Test1 " verticalalignment="Top" click="btDisableSC_Click" height="20" grid.columnspan="2" />
</stackpanel>
</grid>
</window>
---------------------------------------------------
.cs
---------------------------------------------------
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication3
{
public partial class MainWindow : Window
{
string strXMLDataSourceFLDR = Environment.GetEnvironmentVariable("APPDATA") + "\\MyApplicationFLDR";
string strSourceHostsTXT = Environment.GetEnvironmentVariable("APPDATA") + "\\MyApplicationFLDR\\Hosts.TXT";
string strHostName;
ArrayList alHosts = new ArrayList();
public MainWindow()
{
funcCheckHostDataSource();
funcReadHostsFile();
InitializeComponent();
funcPopulatetbHostname();
}
public void funcCheckHostDataSource()
{
if (!Directory.Exists(strXMLDataSourceFLDR))
{
Directory.CreateDirectory(strXMLDataSourceFLDR);
}
if (!File.Exists(strSourceHostsTXT))
{
using (StreamWriter objSWFile = File.CreateText(strSourceHostsTXT))
{
objSWFile.Close();
}
}
}
public void funcReadHostsFile()
{
using (StreamReader objSRFile = File.OpenText(strSourceHostsTXT))
{
string strReadLine = "";
while ((strReadLine = objSRFile.ReadLine()) != null)
{
alHosts.Add(strReadLine.ToLower());
}
objSRFile.Close();
}
}
public void funcPopulatetbHostname()
{
tbHostname.ItemsSource = alHosts;
}
private void btDisableSC_Click(object sender, RoutedEventArgs e)
{
if (this.tbHostname.Text == String.Empty)
{
MessageBox.Show("Please fill in the Hostname of the target System!");
}
else
{
strHostName = tbHostname.Text.Replace("\\", "");
funcUpdateCombobox1(strHostName);
}
}
public void funcUpdateCombobox1(string strNewHostName)
{
ArrayList alHostsNew = new ArrayList();
alHostsNew.Add(strNewHostName.ToLower());
foreach (string item in alHosts)
{
int alHostsNewCount = alHostsNew.Count;
if (alHostsNewCount <= 14)
{
if (strNewHostName != item)
{
alHostsNew.Add(item);
}
}
}
using (StreamWriter objSWFile = File.CreateText(strSourceHostsTXT))
{
foreach (string item in alHostsNew)
{
objSWFile.WriteLine(item);
}
objSWFile.Close();
}
alHosts = alHostsNew;
tbHostname.ItemsSource = alHostsNew;
}
}
}
---------------------------------------------------