|
thank you very much.that's working. i was trying with System.IO.Path.GetFileName.
|
|
|
|
|
I am working on a program which loads rich text documents into a RichTextBox control. What I need is to grab the text of the current "line" (including any text that may have wrapped around to the following line) that I have my insertion point at in the text. I had thought that I might be able search backward as well as forward for the closest System.Environment.NewLine (capturing the index of each) and then do a Sting.Substring call using the indexes of each NewLine find, but for some reason, that is not working.
Are there any suggestions for how I could do this with greater success?
Thanks in advance.
-- modified at 23:38 Thursday 26th July, 2007
John 3:16: "For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life."
using Earth.Internet.WWW.CodeProject;
|
|
|
|
|
Two kinds of lines in RichTextBox:
1) The lines separated by newline characters i.e. richTextBox.Lines[]
2) Lines that wrap in the control
Get 2) using GetFirstCharIndexOfCurrentLine, GetLineFromCharIndex(richTextBox.SelectionStart) etc
A combination of these functions and properties should be what you need.
Good Luck.
|
|
|
|
|
Thanks for your suggestions. It looks like they have gotten me closer to what I am trying to achieve.
Take the below example:
Title
This is the third line of text.
This is the fourth line of text that
by example would wrap to the next line.
Currently, when having my insertion point in any of the first four lines, the result is as expected: I only get the line that I have my insertion point at. When I venture to the fifth line which is really for the purposes of this example a wrapped continuation of the fourth, it counts as the fifth line. How do I tell the difference between a line that is the result from wrapping text and one that is divided by a new line/return carriage?
Thanks in advance.
John 3:16: "For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life."
using Earth.Internet.WWW.CodeProject;
|
|
|
|
|
I'm sure there are several solutions but my first thought is as follows: e.g.
first
second
third
fourth that wraps fourth that wraps fourth that wraps fourth
that wraps
string[] lines = richTextBox.Lines;
i.e.
lines[0] returns "first",
lines[3] returns "fourth that wraps fourth that wraps fourth that wraps fourth that wraps".
1) Create a class LineClass with properties: int FirstCharacter, int LastCharacter, string Line.
2) Add an entry for each line to a List<LineClass>. Remember there is a return character between lines so that in my example:
first instance of LineClass FirstCharacter=0, LastCharacter=4, Line=first
second instance of LineClass FirstCharacter=6, LastCharacter=11, Line=second
3) Use GetFirstCharIndexOfCurrentLine to determine the cursor location.
4) Loop through List<LineClass> to get the line you need.
If the line is a result of wrapping, your answer in 3) will fall between FirstCharacter and LastCharacter for that entry. Otherwise it will equal FirstCharacter.
Good Luck.
|
|
|
|
|
Hello everyone,
I was wonder if there is a way that I can programetically know if a DataTable has been created?
Thank you very and have a great day.
Khoramdin
|
|
|
|
|
What do you mean by 'created' ? You can check if it's not null. Or do you mean if it contains anything ? You can check if it has any rows (Rows.Count, or Rows.Length, at a guess )
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Khoramdin wrote: I was wonder if there is a way that I can programetically know if a DataTable has been created?
What do you mean?
Please do more spesific
Regards,
TomiEdy
|
|
|
|
|
|
Hello everyone,
I have a string which is consists of two sections/strings seperated by "_", ect. "StringOne_StringTwo".
Can someone tell me how I can seperate the two strings?
Thank you very much and have a great day,
Khoramdin
|
|
|
|
|
|
string[] theSplitStrings = theString.Split('_');
|
|
|
|
|
|
Hi
Not being cynical, but are you reading quetsions on CP, writing the answers on your own site, and then attempting to redirect the OP to it, in hope of generating revenue? Put your own site in your signature and put the actual answer in the thread. If your answers are good, you will get people visiting your site anyway.
Regards
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
|
|
|
|
|
Haha.. not bad to have someone from the other side of the world having the same sense. You are as smart as you named. Thanks for the advice and I shall write my answer on both the thread and the website.
Btw, besides generating revenue, I am
1. Increasing my code collection
2. Polishing my programming skills
3. Pretending to be busy infront of my boss
Enjoy your day!
Eliz.K
|
|
|
|
|
Hello,
I have 30 thousand records. What would be the best and fastest way to populate the grid?
DataSource is the way to go I think.
Thank you.
-- modified at 16:40 Thursday 26th July, 2007
|
|
|
|
|
Yep, that would work.
|
|
|
|
|
Remember to use paging on your data grid.
Eliz.K
www.oin1.com
|
|
|
|
|
30 thousand records in one single grid? Why do you want to do this? No user can scroll through 30 thousand of records!
-^-^-^-^-^-
no risk no funk
|
|
|
|
|
Dude, did you see the topic of this thread?
Did I ask your oppinion if I should populate 30 thousand records or not?
IF you have no suggestions, don't post.
|
|
|
|
|
Yeah i can read.
But you give very few information about what you really want to do. And my opinion is that is is very important to know what your application should do to provide a good solution (and you asked for the best).
So I could just say that you should go ahead and put all records into a DataTable and set it as the DataSource of the grid, call DataBind and wait for your browser rendering the page.
Or I could say, no better use an ObjectDataSource or SqlDataSource that provides the data to the grid, because this way you could implement paging, sorting much simpler.
But both ways are surely not the BEST ways to do it, but without knowing what you want to accomplish, I can not give you a better answer that the ones you already received.
So, sorry I tried to help - won't happen again.
-^-^-^-^-^-
no risk no funk
|
|
|
|
|
Say I have two DataTables in a dataset, Product and ProductType. Product has a column id that is a foreignkey in the ProductType table. I setup a datarelation between the two datatables, now how can I display all of the records from the Product datatable and the ProductType datatable in one datagridview? I've found lots of examples of setting up a master/slave relationship with two seperate datagridviews, but none with just using one.
Thanks,
David
|
|
|
|
|
Does anyone know a good C# to mono converter?
Thanks!
Sean Murphy
"All things great and small start at the same point, the first step."
|
|
|
|
|
Mono is a C# compiler not a separate language. If you're looking for a tool to change all the places your code uses something that the mono project hasn't gotten around to implementing, afaik there isn't one.
--
You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer
|
|
|
|
|
You have a misunderstanding of Mono, my friend. Mono is a programming framework, like the .NET framework. You can use C# in Mono just like you can in .NET. You don't need to convert C# to anything to run it on Mono. If your C# code uses some library, say a native Win32 library, then you'll need to change it to use something more cross-platform.
AFAIK, there is no converter that automatically makes your project run on Mono. If you used purely the .NET framework, chances are it will compile OK on Mono. You can use the Moma[^] tool to see if you need to make any changes to your code for it to work on Mono.
|
|
|
|