Selecting Specific Text in a TextBox

How to specify what text to select in a TextBox using textBox.Lines

Page 1 of 1

6 Replies - 1911 Views - Last Post: 03 November 2009 - 01:08 PM Rate Topic: -----

#1 Grapevine  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 55
  • Joined: 26-October 09

Selecting Specific Text in a TextBox

Posted 03 November 2009 - 10:37 AM

Hello,

I am working on another project for a friend. They are in this program where they have to apply for at least 15 jobs every week. They have to Apply for the job online and write an email of all the jobs they applied for and email them to whoever.

To make this task easier, they have asked me to develop a simple program where they may enter the job details and have the program automatically write an email with all the jobs. Simple enough concept.

I have pretty much completed this project. However, there is something I have not yet figured out. I have allowed the user to log up to 20 jobs in one session. The user may continue to add jobs until they reach 20. I have also allowed them to remove any job entry by use of a button.

When this button is clicked, it removes the job details from a hidden datagrid and from the actual job log interface. However, I also have an Email Preview TextBox that updates the email preview with every job that is added. When the remove job button is pressed, I cannot get it to remove the text from the Preview TextBox!

Below is an example of what an email preview may look like with a few jobs added to the log:



Job No. 1
Date: 11/3/2009

Company: Joe Blow Company
Title: Engineer
Salary: 19.50

11750 Joe Plaza Dr.
Tower 5
Somewherein, VA 28888

Phone: 555-555-8854
Fax: 555-555-8859
Email: myemail@site.com

Additional info. This is a test job entry.

-----------------------------------------

Job No. 2
Date: 11/3/2009

Company: Another Company
Title: Sales Associate
Salary: 14.00



Somewherein, CA 78554

Phone:
Fax:
Email:

Not much more info....

-----------------------------------------

Job No. 3
Date: 11/3/2009

Company: JobsAnonymous
Title: Customer Service
Salary: 9.00



,

Phone:
Fax:
Email: apply@jobsanonymous.com

another test

-----------------------------------------




As you can see, some jobs may have the address info, some may not. So sometimes the user may enter all information, sometimes not. If the user wanted to remove Job No. 2, how can I get the TextBox to remove only that text in between Job 1 and 3?

Am I making much sense? I want it to select only that specific Job from the TextBox and remove it. Is this at all possible??? I know it is possible to select specified text from an integer start point and length, but how can I specify this in a TextBox full of text??


Any help would be greatly appreciated! Sorry for the long story......I have searched and tried to code it myself, but I cannot get it to work.

AS I have it now, the code below clears the row in the datagrid and the job in the interface. The clearOneJob() method clears the text boxes on the interface, fyi....Somewhere in this Click event I want the textbox to remove the specific job:

private void closeJobButton_Click(object sender, EventArgs e)
		{
			int jobLabelInteger = Convert.ToInt32(jobLabel.Text);
			int closeThisJob = (jobLabelInteger - 1);

			if (MessageBox.Show("Are you sure you want to remove Job #" + jobLabel.Text + " from the log?", "Remove Job #" + jobLabel.Text + "?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
			{
				jobsDataGrid.Rows[closeThisJob].Cells[0].Value = null;
				jobsDataGrid.Rows[closeThisJob].Cells[1].Value = null;
				jobsDataGrid.Rows[closeThisJob].Cells[2].Value = null;
				jobsDataGrid.Rows[closeThisJob].Cells[3].Value = null;
				jobsDataGrid.Rows[closeThisJob].Cells[4].Value = null;
				jobsDataGrid.Rows[closeThisJob].Cells[5].Value = null;
				jobsDataGrid.Rows[closeThisJob].Cells[6].Value = null;
				jobsDataGrid.Rows[closeThisJob].Cells[7].Value = null;
				jobsDataGrid.Rows[closeThisJob].Cells[8].Value = null;
				jobsDataGrid.Rows[closeThisJob].Cells[9].Value = null;
				jobsDataGrid.Rows[closeThisJob].Cells[10].Value = null;
				jobsDataGrid.Rows[closeThisJob].Cells[11].Value = null;
				jobsDataGrid.Rows[closeThisJob].Cells[12].Value = null;

				clearOneJob();
			}
		}





Thanks,

This post has been edited by Grapevine: 03 November 2009 - 01:06 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Selecting Specific Text in a TextBox

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Selecting Specific Text in a TextBox

Posted 03 November 2009 - 10:55 AM

You can regenerate the preview email or you can grab the Lines property from the textbox and remove what you need.
Was This Post Helpful? 1

#3 Grapevine  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 55
  • Joined: 26-October 09

Re: Selecting Specific Text in a TextBox

Posted 03 November 2009 - 11:24 AM

hmm...alright....

I'll have to look up the textBox.Lines property I guess. I know you all dont like to give me my code for me, but a simple example would help tremendously! Please if you have even the simplest example, I can figure it out and incorporate it into my project. I just need a jumpstart.

Either way, thank you very much, as always!
Was This Post Helpful? 0
  • +
  • -

#4 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Selecting Specific Text in a TextBox

Posted 03 November 2009 - 12:33 PM

String[] theText = textBox1.Lines;

// Lets say we want to remove lines from 8 - 15
int lower = 8;
int upper = 15;
String[] newText = new String[theText.Length-(upper-lower+1)]

int pos = 0;
for (int i = 0; i < theText.Length; i++) {
	if (i < lower || i > upper) {
		newText[pos] = theText[i];
		pos++;
	}
}

textBox1.Lines = newText;

Was This Post Helpful? 1
  • +
  • -

#5 Grapevine  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 55
  • Joined: 26-October 09

Re: Selecting Specific Text in a TextBox

Posted 03 November 2009 - 12:59 PM

Wow thanks a lot.

This should help a lot! I am going to change this specific to my project and see how it works.

Another question pertaining to this example....

What if you have a textBox that constantly changes? For example, when the user removes a job, the textBox will be updated and those lines will be gone. Now the lines will change.....Job 3 will now be where Job 2 was before.

Will the lines that I remove be replaced with empty lines or will they be totally removed? Maybe this is something I have to try first and see how it works? Either way, I am going to try it and figure it out on my own. But I figured I would ask first.

Thank you very much, as always.
:D



Edit....
I am realizing that this last question may not have an answer...It seems like something I might have to just do.....I will have to rework it so that it fits my project I guess. Should be fun to figure out though. :)

This post has been edited by Grapevine: 03 November 2009 - 01:02 PM

Was This Post Helpful? 0
  • +
  • -

#6 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Selecting Specific Text in a TextBox

Posted 03 November 2009 - 01:06 PM

The lines removed by my code are gone, not just replaced with blanks.
Was This Post Helpful? 0
  • +
  • -

#7 Grapevine  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 55
  • Joined: 26-October 09

Re: Selecting Specific Text in a TextBox

Posted 03 November 2009 - 01:08 PM

View PostMomerath, on 3 Nov, 2009 - 12:06 PM, said:

The lines removed by my code are gone, not just replaced with blanks.


Thank you, sir.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1