开发者

When a menubox is chosen, a textbox has to appear, so that the user may enter some values

When a menubox is chosen, a textbox has to appear, so that the user may enter some values

I have made a program that results this program. The program is a csv parser.

I need this thing to happen : when I select "alfarithmitiko" then a textbox (may be something else you will suggest) will appear, where the user can enter some words, jobs more specifically, lets say "doctor" "chemist" "developer" "technician".

I will take the jobs and check that the columns have the these words only. For example the 3rd column is job , so , it is expected to have i开发者_C百科n its fields olny the words "doctor" "chemist" "developer" "technician".

THank you very much

public partial class Form1 : Form
    {


        ArrayList fileList = new ArrayList();
        string stringforData;


        public Form1()
        {
            InitializeComponent();
            dataGridView1.Columns[0].ReadOnly = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //  Anoigei to parathuro **BROWSE**

            openFileDialog1.Title = "Epilexte Arxeio CSV Gia Elegxo ";

            string filename = "";
            DialogResult result = openFileDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                filename = openFileDialog1.FileName;

                textBox1.Text = filename;






                string line;
                // Read the file and display it line by line.

                //diavazei apo to textbox to path
                System.IO.StreamReader file = new System.IO.StreamReader(textBox1.Text);

                stringforData = file.ReadLine();      // Auth thn grammh thn ebala gia na mhn diabazei thn prwth grammh 
                while ((line = file.ReadLine()) != null)
                {
                    // bazei stoixeia mesa ston pinaka 
                    fileList.Add(line.Split(';'));
                }

                file.Close();



                this.ToDataGrid();
            }
        }






private void button2_Click(object sender, EventArgs e)
        {
            this.textBox2.Clear();
    //*************  COLUMN 2 SE STRING[]  ************************************
            string[] colB = new string[dataGridView1.Rows.Count];

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {

                colB[i] = Convert.ToString(dataGridView1.Rows[i].Cells[1].Value);
               File.WriteAllLines("settings2.txt", colB);
            }
    //*************************************************************************

            for (int i = 0; i < fileList.Count; i++)// perna mia mia tis grammes 
            {
                string[] lineItems = (string[])fileList[i];// pinakas apo string 

                for (int j = 0; j < colB.Length; j++)
                {
                    //     Noumera-IDs
                    //textBox2.Text += "edw mphka, einai meta ta 2 for";// edw mpainei kanonika 
                    if (colB[j] == "arithmos")
                    {


                        if (!arithmos(lineItems[j]))

                            textBox2.Text += "To stoixeio    " + lineItems[j] + "\tsthn sthlh "+ j +" prepei na einai arithmos" + Environment.NewLine;
                    }
                    if (colB[j] == "alfarithmitiko")
                    {


                        // alfarithmitiko  
                        if (!numword(lineItems[j]))
                            textBox2.Text += "To stoixeio    " + lineItems[j] + "   sthn sthlh " + j + " einai lathos grammeno" + Environment.NewLine;
                    }
                    //grammata 
                    if (colB[j] == "grammata")
                    {

                        if (!word(lineItems[j]))
                            textBox2.Text += "To stoixeio    " + lineItems[j] + "   sthn sthlh " + j + " prepei na einai leksh" + Environment.NewLine;
                    }
                    }
                    }
                        // EDW THA APOTHUKEUW SE ARXEIO 


        }

      //roufa ta dedomena apo thn deuterh sthlh kai bale ta se ena string[] to opoio legete stringFromGrid
    //foreach (string a in stringFromGrid[])
    //    { 
    //         if (stringFromGrid[a]=="arithmos") 
    //              {
    //              if (!arithmos(kati me arrayList))
    //              textBox2.Text += "To stoixeio    " + ?????????? + "\tsthn sthlh 7 prepei na einai arithmos" + Environment.NewLine;
    //              } 
    //      if (stringFromGrid[a]=="grammata") 
    //                 {
    //              if (!word(kati me arrayList))
    //              textBox2.Text += "To stoixeio    " + ?????????? + "\tsthn sthlh 7 prepei na einai arithmos" + Environment.NewLine;
    //                 }
    //      if (stringFromGrid[a]=="alfarithmitiko")
    //                if (!numword(kati me arrayList))
    //              textBox2.Text += "To stoixeio    " + ?????????? + "\tsthn sthlh 7 prepei na einai arithmos" + Environment.NewLine;
    //                 }
    //    }
            //if (textBox2.Text.Trim().Length == 0)
           // {
            //    textBox2.Text = "den uparxei sfalma ";
          //  }




        public void ToDataGrid()
        {
            string[] split = stringforData.Split(';');


            foreach (string item in split)
            {
                dataGridView1.Rows.Add(item);
            }
            File.WriteAllLines("settings1.txt", split);
        }





        public bool arithmos(string a)
        {

            return Regex.IsMatch(a, (@"^\d*$"));

        }

        public bool word(string a)
        {

            return Regex.IsMatch(a, (@"^[a-zA-Z]*$"));

        }

        public bool numword(string a)
        {

            return Regex.IsMatch(a, (@"^[0-9a-zA-Z_]*$"));

        }


You need to bind to the CellEndEdit event of the DataGrid, figure out which cell has been edited by looking at the DataGridViewCellEventArgs and then display your text box. Something like:

private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
    var cell = dataGridView1[e.ColumnIndex, e.RowIndex];
    if (cell.Value.Equals("alfarithmitiko"))
    {
        MyHiddenText.Visible = true;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜