Click to See Complete Forum and Search --> : working with text file
tis707
November 29th, 2008, 04:48 AM
Hi all
i have to rewirte the content of the text file
my text file look like below
BBC|1045|132|some text
BBC|1045|134|some text
BBC|1045|136|some text
BBK|1047|134|some text
BBK|1047|138|some text
BBK|1047|142|some text
i have to show up the first one BBC in one combo box based on selection need to show the
third parameter in another combo box , based on second combo box selection need to show the "some text" in a text box
there in text box user can change the text and click to save and the text file should be updated
which one is the bset approach to get unique names of first column to show in combo box
Thanks a lot
Homogenn
November 29th, 2008, 07:18 AM
I'd use a Dictionary, List or simply a String array, combined with a class to contain lists of the rest.
toraj58
November 29th, 2008, 07:47 AM
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.
tis707
November 30th, 2008, 11:06 PM
Thanks for your replies
Could you pls show me with some piece of code
is the multi dimensional array is the correct approach
toraj58
December 2nd, 2008, 04:33 AM
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.
tis707
December 2nd, 2008, 11:49 PM
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
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.