Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Topics

Recent Status Updates

View All Updates

Photo
- - - - -

Writing multiline txt to richTextBox - data from checbkoxes


  • Please log in to reply
6 replies to this topic

#1 Bushby207

Bushby207

    CC Lurker

  • Just Joined
  • Pip
  • 5 posts

Posted 31 January 2011 - 06:42 AM

As this is my first post I apologise in advance for any mistakes I make..

1) I'm trying to add text to "richTextBox1" as stage 1 of a larger application.
2) The text is data coming from checkboxes
3) When CheckBox1 is checked and the "EnterDataButton" is pressed the text is entered in the box as the code says, however, if more than one box is checked, only the most senior piece of text is entered.
For instance, if boxes 1+2 are checked then only the text for box 2 will be entered and if 3+9 then only txt relating to 9 will be entered.

4) My goal is to enter the relevant txt for all checked boxes on a new line of "richTextBox1"
5) Further to this, once the data is collected in "richTextBox1" i'd like to save it to a file.

so what have i tried......... I've had a play around with \n and \r but failed miserably.
I've also tried playing with the if argument and again failed..

any help would be great..

private void EnterDataButton_Click(object sender, EventArgs e)
        {
           if (checkBox1.Checked) richTextBox1.Text = ("box1 done");
           if (checkBox2.Checked) richTextBox1.Text = ("box2 done");
           if (checkBox3.Checked) richTextBox1.Text = ("box3 done");
           if (checkBox4.Checked) richTextBox1.Text = ("box4 done");
           if (checkBox5.Checked) richTextBox1.Text = ("box5 done");
           if (checkBox6.Checked) richTextBox1.Text = ("box6 done");
           if (checkBox7.Checked) richTextBox1.Text = ("box7 done");
           if (checkBox8.Checked) richTextBox1.Text = ("box8 done");
           if (checkBox9.Checked) richTextBox1.Text = ("box9 done");
           if (checkBox10.Checked) richTextBox1.Text = ("box10 done");

If it's any help, i'm using Microsoft Visual C# 2010 Express
  • 0

#2 Bushby207

Bushby207

    CC Lurker

  • Just Joined
  • Pip
  • 5 posts

Posted 31 January 2011 - 10:45 AM

I am Getting Closer with the following code,


private void EnterDataButton_Click(object sender, EventArgs e)
        {

            String A;
            String B;
            String C;
            String D;
            String E;
            String F; 
            String G;
            String H;
            String I; 
            String J;
            
            
            
            if (checkBox1.Checked)
                A = ("\r\n CB1");
            else A = (null);

            if (checkBox2.Checked)
                B = ("\r\n CB2");
            else B = (null);

            if (checkBox3.Checked)
                C = ("\r\n CB3");
            else C = (null);

            if (checkBox1.Checked)
                D = ("\r\n CB4");
            else D = (null);

            if (checkBox2.Checked)
                E = ("\r\n CB5");
            else E = (null);

            if (checkBox3.Checked)
                F = ("\r\n CB6");
            else F = (null);

            if (checkBox1.Checked)
                G = ("\r\n CB7");
            else G = (null);

            if (checkBox2.Checked)
                H = ("\r\n CB8");
            else H = (null);

            if (checkBox3.Checked)
                I = ("\r\n CB9");
            else I = (null);

            if (checkBox3.Checked)
                J = ("\r\n CB10");
            else J = (null);


             textBox1.Text = A+B+C+D+E+F+G+H+I+J;

I now need this info to be placed into a file on my HD.

Any ideas?
  • 0

#3 Bushby207

Bushby207

    CC Lurker

  • Just Joined
  • Pip
  • 5 posts

Posted 31 January 2011 - 12:17 PM

I think i'm solving my own problems here but incase anyone has any bright solutions to any of the problems i face in this application here's the code so far..

My next issue will be to insert this data into an existing excel document.... Any help would be great.
The other issue i have is that i have over 500 names and surnames to enter from an excel document, do you think there's a way i could get this data into the .cs with a .csv or similar.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void EnterDataButton_Click(object sender, EventArgs e)
        {

            String date = dateTimePicker1.Value.ToString("dd-mm-yyyy \r\n");
            
            string setup = ("Name, Sirname, Attendance");

            string blank = ("\r\n");

            string total = (",,=Sum(a3:a12)");

                
            String A;
            String B;
            String C;
            String D;
            String E;
            String F; 
            String G;
            String H;
            String I; 
            String J;
            
            
            
            if (checkBox1.Checked)
                A = ("\r\n Bill, Bayley, 1");
            else A = (null);

            if (checkBox2.Checked)
                B = ("\r\n CB2");
            else B = (null);

            if (checkBox3.Checked)
                C = ("\r\n CB3");
            else C = (null);

            if (checkBox4.Checked)
                D = ("\r\n CB4");
            else D = (null);

            if (checkBox5.Checked)
                E = ("\r\n CB5");
            else E = (null);

            if (checkBox6.Checked)
                F = ("\r\n CB6");
            else F = (null);

            if (checkBox7.Checked)
                G = ("\r\n CB7");
            else G = (null);

            if (checkBox8.Checked)
                H = ("\r\n CB8");
            else H = (null);

            if (checkBox9.Checked)
                I = ("\r\n CB9");
            else I = (null);

            if (checkBox10.Checked)
                J = ("\r\n CB10");
            else J = (null);

            
            richTextBox1.Text = date+setup+A+B+C+D+E+F+G+H+I+J+blank+total;

            


           
            
               




        }

        private void SaveButton_Click(object sender, EventArgs e)
        {

            String date;
            date = dateTimePicker1.Value.ToString("dd-mm-yyyy");


            // Create a SaveFileDialog to request a path and file name to save to.
   SaveFileDialog saveFile1 = new SaveFileDialog();

   // Initialize the SaveFileDialog to specify the RTF extension for the file.
            saveFile1.DefaultExt = "*.csv";
            saveFile1.Filter = "CSV Files|*.csv";
            saveFile1.InitialDirectory = (@"C:\FOLDER REFERENCE.....");
            saveFile1.FileName = (date);

   // Determine if the user selected a file name from the saveFileDialog.
   if(saveFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
      saveFile1.FileName.Length > 0) 
   {
      // Save the contents of the RichTextBox into the file.
      richTextBox1.SaveFile(saveFile1.FileName, RichTextBoxStreamType.PlainText);
   }
            
        }
    }
}

  • 0

#4 CommittedC0der

CommittedC0der

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1065 posts
  • Programming Language:C#
  • Learning:C#, JavaScript, PL/SQL

Posted 31 January 2011 - 12:19 PM

You mean like write teh text from the textBox into a .txt file on your HD?

Try this tutorial.
http://forum.codecal...text-files.html
  • 1
There IS a war going on for your mind.
Nothing of eternal significance happens besides prayer.

#5 Bushby207

Bushby207

    CC Lurker

  • Just Joined
  • Pip
  • 5 posts

Posted 31 January 2011 - 12:27 PM

i managed to get the data into a csv where i can read it as an excel document which is great....

now i need to get this data into an existing excel document without disturbing other data already in it

thanks for the link the system i/o and knowing how to use the \r\n were vital
  • 0

#6 CommittedC0der

CommittedC0der

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1065 posts
  • Programming Language:C#
  • Learning:C#, JavaScript, PL/SQL

Posted 01 February 2011 - 03:55 PM

Hmm, not sure but this may help.
How to transfer data to an Excel workbook by using Visual C# 2005 or Visual C# .NET

~ Committed.
  • 0
There IS a war going on for your mind.
Nothing of eternal significance happens besides prayer.

#7 Bushby207

Bushby207

    CC Lurker

  • Just Joined
  • Pip
  • 5 posts

Posted 02 February 2011 - 02:42 AM

It's pretty good, i'd looked before at this and it does work.

I Kind of hoped there was an easier way, some kind of automation.. i'll work with this for now and tweak it as and when i have time.

Cheers Dude!
  • 0




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download