I have two listbox, which have characters like:
Listbox1 Listbox2
Model1 Price1
Model2 Price2
Model3 Price3
Model4 Price4
I want to display both lists in a listbox3, in this way:
Listbox
Model1,Price1
Model2,Price2
Model3,Price3
Model4,Price4
I've tried to combine the list but I got the error:
System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index'
///
///Modelos
///
public string[] _EModelsArray;
public string[] _ModelsArray;
public string[] _UnionArray;
StreamReader _reader = new StreamReader(@".\MODELOS.txt"); // Abre el archivo de texto
List<string> _info = new List<string>();
while(!_reader.EndOfStream)
{
string _line = _reader.ReadLine().Trim();
string [] _tokens = _line.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
///
/// crear el listado
///
var _Model = new List<string>();
var _EModel = new List<string>();
var _Union = new List<string>();
//var _EQty = new List<string>();
if (_tokens.Length == 2)
{
_Model.Add(_tokens[0]);
_EModel.Add(_tokens[1]);
//_EQty.Add(_tokens[2]);
}
//else
//MessageBox.Show("Error!!!");
///
/// Convertir en array
///
_ModelsArray = _Model.ToArray();
_EModelsArray = _EModel.ToArray();
foreach (var item in _ModelsArray)
{
listBox1.Items.Add(item);
}
foreach (var item in _EModelsArray)
{
listbx2.Items.Add(item);
}
for (int i = 0; i <=30; i ++)
{
_Union[i] = _Model[i] + _EModel[i];
}
_UnionArray = _Union.ToArray();
foreach (var item in _UnionArray)
{
listbx_union.Items.Add(item);
}
whereas I am working for:
Listbox3
Model1,Price1
Model2,Price2
Model3,Price3
Model4,Price4
Model and price combined into 1 line.