private void Form_Load()
{
_loading = true;
try
{
//external library LayoutHelper
LayoutHelper helper
= new LayoutHelper
(); string caption = helper.getDWGName(FilenameStyle.Elipsed);
Dictionary<string, string> cs = helper.getLayouts().ToDictionary();
//Bind layout info to combobox
cbxLayouts
.ComboBox.DataSource = new BindingSource
(cs,
null); cbxLayouts.ComboBox.DisplayMember = "Value";
cbxLayouts.ComboBox.ValueMember = "Key";
//_initialLayout is "Model" or a string passed in the constructor -1 returned if no matching layout found
cbxLayouts.SelectedIndex = getFirstIndexOf(_initialLayout, cs);
if (cbxLayouts.Text != "")
{
//Get the xRecords with the matching layout handle (primary) or name (secondary)
_data = helper.getXrecords(((KeyValuePair<string, string>)cbxLayouts.SelectedItem()).Key, ((KeyValuePair<string, string>)cbxLayouts.SelectedItem()).Value);
}
}
catch{}
_loading = false;
}
private void cbxLayouts_SelectedIndexChanged(object sender, EventArgs e)
{
if (!_loading)
{
try
{
_data = helper.getXrecords(((KeyValuePair<string, string>)cbxLayouts.SelectedItem()).Key, ((KeyValuePair<string, string>)cbxLayouts.SelectedItem()).Value);
}
catch{}
}
}
//Find index of a given value in a Dictionary<string, string>
//-1 if not found
public int getFirstIndexOf(string search, Dictionary<string, string> mydict)
{
int i = 0;
foreach (KeyValuePair<string, string> item in mydict)
{
if (item.Value == search)
{
return i;
}
i++;
}
return -1;
}