Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wrapping text within a database field

Status
Not open for further replies.

Phil Thoms

Programmer
Oct 31, 2005
245
0
16
GB
Hello,
I have a database within a grid and one of the fields is 80 characters long, is it possible to wrap this particular field to say 40 characters over 2 lines? I know this is easy to achieve in the report writer but cannot find any help regarding database field wrapping.

Thanks
 
You can't wrap a field "in a database". That doesn't make sense.

What you can do is wrap a field when you display it in a form. You do that by using an edit box (not a text box). The edit box automatically displays wrapped text, with a vertical scroll bar if necessary.

You also mention a grid. Grids don't normally display wrapped text, but there is nothing stopping you from putting an edit box into one of the columns of the grid - although I'm not sure how effective that would be. If you need help doing that, come back.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Well, report wrapping also does not wrap the data, only the output.

Within forms the objects doing wrapping are controls, even thinking of caode changing the values to include a CRLF at some place, it's controls displaying the text, only controls and their capability to display more than one row are of interest.

In a grid you have a textbox per column and multiple rows drawn, you can have a dynamiccurrentcontrol in a column, you can set a columns display to use the column control only at the active current row viw sparse and - well - you can specify a different contral than textbox for a column in every row.

What control displays wrapped text? An editbox, correct. So the outset is clear, add an editbox to the grids column of interest. Setting it the currentcontrol is sufficient, you don't want to dynamically change from textbox to editbox and back, an editbox can also display short texts.

But don't expect this to create individual row heights depending on wrapping or not wrapping. You either set the height to be able to display two text lines or you need to get down to the tricky use of some - any - dynamiccurrentproperty to let it set the rowheight depending on the height needed to show the wrapped text. That's not only tricky because of having code processing every row displayed but also since you need to find out whether text wraps and what its height is, if it wraps.

So in the end: Not simple to do, if at all. An excel table/sheet has that quite easily built in via setting column height to autofit mechanisms. You'd need to do such a beast yourself, an algorithm for autofitting.

Bye, Olaf.
 
Having read your question again, I wonder if you mean that you want to split the field into two separate fields, each 40 characters wide, and store them that way in the database.

If so, obviously you could simply do this:

Code:
lcText = " .... < 80 characters here > ..."
lcT1 = LEFT(lcText, 40)
lcT2 = RIGHT(lcText, 40)

But that would blindly split it at the 40th character, even if it was in the middle of a word.

If you want to split so as not to divide a word:

Code:
lcT1 = MLINE(lcText, 1, 40)
lcT2 = MLINE(lcText, 2, 40)

But I'm really just guessing that this is what you want to achieve. If neither of my answers help, perhaps you could clarify your quesion.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hello again,
Great, I'll go with the idea of the edit box and a greater row height which seems the best fit what I've done so far.
I originally thought that there would be an Autofit type property that could kick in when necessary.
If I get stuck (or whatever) I'll let you know.

Thanks for your help.
 
Be careful with long texts in grids, if they aren't in an edit box they can cause crashes.


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
It might not be what you are looking for, but when one of my clients had a LONG text field to display (either Long Character or Memo), I merely had a shortened version displayed in the Form Grid.
That shortened (abbreviated) version was enough to let the user know:
1. There was more to look at
2. It conveyed the gist of the content.

Then when the user wanted to read ALL of the long text they could click on the textbox. When they did the Form's Grid Textbox's Doubleclick method popped up a secondary form with that data displayed in Full.

In that way, the primary form and its information was easy to read and yet allowed the user access to that specific information (ALL of it) on those instances that it was needed.

And on another client system, I had a similar approach to the Grid, but I had an Editbox on the form (not in the Grid), As the user scrolled down through the Grid, the separate Editbox was populated with the FULL text from the Grid's current record - thereby enabling the user to read it.

Good Luck,
JRB-Bldr
 
If you search you also find another thread here were a proposed solution was to populate the grids tooltiptext in the mousover of a textbox with a too long text. That triggers displaying that tooltip even despite the grids tooltip bug, I think. So you might also give that a try.

Bye, Olaf.
 
I had a similar approach to the Grid, but I had an Editbox on the form (not in the Grid), As the user scrolled down through the Grid, the separate Editbox was populated with the FULL text from the Grid's current record - thereby enabling the user to read it.

Now you mention it, that's an obvious way of handling the situation. I suspect it's the one that most of us would go for.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks for all these ideas. I am using VFP6 and as this particular problem became urgent, I used a condensed typeface which nearly halved the length of the field in question and looked fine, it gives space for extra fields if necessary.
 
and look out for long memos in grids, sometimes they can make the form hang

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Thanks for your replies.
Mike,
I had to achieve something very quickly at that particular moment in time. However, your second suggestion looks good but how do you show the 2 lines in one column, do the properties have a function for this? Or am I missing something more obvious?

Thanks again.
 
your second suggestion looks good but how do you show the 2 lines in one column,

When I made that suggestion, it was before we had definitely established that you wanted to show two lines in a column of a grid. We were still talking about "wrapping text within a database field". My MLINE() suggestion was simply a way of splitting a long piece of text into two chunks, taking account of word boundaries.

That said, it is possible to display two separate lines of text in the same column. The trick is to place a container control in the column, and then to place two text boxes in the container, one below the other. Bind each text box to one of the two pieces of text.

I know that would work, because I have done it a lot myself. But it is only really effective if the grid is read only. In fact, it would be easier to go with the other solution, that is, to place an edit box in the grid. As well as being simpler, it would make editing the text much easier, and would be generally more flexible.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top