Re: working with text file
I'd use a Dictionary, List or simply a String array, combined with a class to contain lists of the rest.
Re: working with text file
your file structrue is Many-to-One relationship and it is not optimize for updating and retriving data.
also you have duplicated name in the second column base on them you should have a control (or bunch of them) in your form to show all related text to the second column.
IMHO it would be better that you change your data structure and them implement something like primary or foreign keys with two files like relational databases. or you can implement an combination of arrays and Link List.
Re: working with text file
Thanks for your replies
Could you pls show me with some piece of code
is the multi dimensional array is the correct approach
Re: working with text file
yes, somewhat you can implement it with Multi Dimensional Array. or ArrayList of ArrayList to have more flexibility for add and remove and extending the lenght.
Re: working with text file
Code:
private void btnLoadFile_Click(object sender, EventArgs e)
{
ArrayList arrProdname = new ArrayList();
ArrayList arrProdParam = new ArrayList();
ArrayList arrProdParamVal = new ArrayList();
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "txt files (*.txt)|*.txt";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
XmlDocument doc = new XmlDocument();
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string fileName = openFileDialog1.FileName;
try
{
using (StreamReader sr = new StreamReader(fileName))
{
String line;
while ((line = sr.ReadLine()) != null)
{
string prdName = "";
string prdid = "";
string prdparameter = "";
string prdParamValue = "";
char[] delimiterChars = { '|' };
string[] words = line.Split(delimiterChars);
prdName = words[0];
prdid = words[1];
prdparameter = words[2];
prdParamValue = words[3];
// MessageBox.Show(line);
// cmbProductList.Items.Add(prdName);
arrProdname.Add(prdName);
arrProdParam.Add(prdparameter);
arrProdParamVal.Add(prdParamValue);
}
sr.Close();
}
}
catch (Exception ex)
{
// Let the user know what went wrong.
MessageBox.Show(ex.Message);
}
}
}
i got values into arraylists
productname into arrprodname
productparametr into arrProdParam
prodparamtervalue into arrProdParamval
but how can i get distinct value into combo box from arrprodname
and if i select a value from combo box how can i get perticular paramters for this selected product
thanks a lot