|
Hello,
When i am trying to copy stringbuilder to string it copies the same string twice or 3 times
for example if i do:
stringbuilder temp=new stringbuilder();
string temp1;
temp1=temp.tostring();
if temp="abc";
then temp1 gets- "abcabcabc"
why is that?
|
|
|
|
|
Try !ispostback
try and try untill reach success..
|
|
|
|
|
|
IsPostback is relevant to ASP.NET. The OP did not say what environment he was using so your answer could be completely irrelevant and worse misleading.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
You haven't shown any code that actually adds values to the stringbuilder. Where is that? Are you calling it multiple times perhaps.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I fount my mistake.
I had a method that returns a stringbuilder and receives a stringbuilder.
for example:
private stringbuilder method1(stringbuilder temp)
{
temp.append("abc");
}
private void main_method()
{
stringbuilder main=new stringbuilder();
main.append(method1(main));
}
something like that
|
|
|
|
|
michaelgr1 wrote: if temp="abc";
Hmmmm....
Show us as much of the actual associated code as you can...
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Hi. i have been wondering for a while, is there any option to retrieve rows from a SQL Server with a startRecord e.g. select top 20 records from position 25, Without any WHERE conditions (without WHERE ID > 25)..
Please advice.
Thanks
|
|
|
|
|
I think there a one way to do this
Retrive all data columns and fill it into dataset and loop it.
try and try untill reach success..
|
|
|
|
|
Hello,
I currently have an unmanaged DLL written in C++ and I can call the exported methods in this DLL from my C# app without any problems and it works quite well.
Now, I need to call from this DLL a method in my managed app. Is it possible to do so? What do I need to do so that the managed method is visible and available to the unmanaged DLL?
Thanks,
Keith
|
|
|
|
|
|
or look at "delegates" and "two-side logging" in this article[^].
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hi!.
I have a report containing a link to view subreport . Now i have to export that in .doc programmatically. I am able to do this . But the subreport is not exported. How to export the report with the subreport.
Thanks
|
|
|
|
|
I have the current data in an excel sheet:
<br />
---A---B---C--<br />
1| 0 | 5 | 1 |<br />
2| 2 | 4 | 2 |<br />
3| 4 | 3 | 3 |<br />
4| 6 | 2 | 4 |<br />
5| 8 | 1 | 5 |<br />
<br />
The values for column A and B are the Y-axis values for two lines in the graph. The C column is the X-axis values which both lines shares.
I would like to create a graph containing two lines based on the data above. I don't understand how to do that. The guides on internet are to general and don't deal with this case.
I have come with this method to plot the graph in the active worksheet.
The "workSheet" object is the active work sheet in my C# application.
public void TestAddChart(XlChartType type, System.Drawing.Point location, Size size)
{
ChartObjects chartObjects = (ChartObjects)workSheet.ChartObjects(Type.Missing);
ChartObject chartObject = chartObjects.Add(location.X, location.Y, size.Width, size.Height);
Chart chart = chartObject.Chart;
Range line1Yvalues = workSheet.get_Range("A1", "A5");
Range line2Yvalues = workSheet.get_Range("B1", "B5");
Range commonXvalues = workSheet.get_Range("C1", "C5");
chart.SetSourceData(line1Yvalues, XlRowCol.xlRows);
chart.SetSourceData(line2Yvalues, XlRowCol.xlRows);
chart.SetSourceData(commonXvalues, XlRowCol.xlRows);
}
I call the method with this code:
classInstance.TestAddChart(XlChartType.xlLine, new Point(100, 100), new Size(300, 300));
When I shut down my application and look in the excel file, I find the result of the graph to be something else. There is instead a bar chart containing five series.
What shall I change to make this work?
|
|
|
|
|
Perhaps the place to start would be using the "type" parameter somewhere in your method?
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
Yes of course, forgot that one Here is the correed version of the method:
public void TestAddChart(XlChartType type, System.Drawing.Point location, Size size)
{
ChartObjects chartObjects = (ChartObjects)workSheet.ChartObjects(Type.Missing);
ChartObject chartObject = chartObjects.Add(location.X, location.Y, size.Width, size.Height);
Chart chart = chartObject.Chart;
Range line1Yvalues = workSheet.get_Range("A1", "A5");
Range line2Yvalues = workSheet.get_Range("B1", "B5");
Range commonXvalues = workSheet.get_Range("C1", "C5");
chart.SetSourceData(line1Yvalues, XlRowCol.xlRows);
chart.SetSourceData(line2Yvalues, XlRowCol.xlRows);
chart.SetSourceData(commonXvalues, XlRowCol.xlRows);
chart.ChartType = type;
}
But the result is still not what I wanted. Here is the new result:
1) No lines in the graph is visible
2) There are five series, it should only be two
3) The Y-axis value is from 0 to 6, it should at least be 0 to 8.
4) The x-axis value is just 1, it should be 1 to 5.
I guess Excel cannot figure out that Line1 and Line2 should share same X-axis values. Or I lack those instructions.
What to do now?
|
|
|
|
|
I have never used c# to access/modify Excel and so do not have a definitive answer to your problem.
However, in this part of your code
chart.SetSourceData(line1Yvalues, XlRowCol.xlRows);
chart.SetSourceData(line2Yvalues, XlRowCol.xlRows);
chart.SetSourceData(commonXvalues, XlRowCol.xlRows);
chart.ChartType = type;
I notice that all three data sources are set to XlRowCol.xlRows , which seems odd to me. Shouldn't, at least, one of them be set to XlRowCol.xlColumns ?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
|
|
|
|
|
Oh yes, you maybe right. I thought the XlRowCol specified how excel should read the data in the sheet. Guess I was wrong.
Anyway I changed commonXvalues's XlRowCol-value from "XlRowCol.xlRows" to "XlRowCol.xlColumns" in the SetSourceData() method call.
The final result is almost what I want. Here is the major issue:
Only one line is displayed. It seems that the line's data is taken from the C column only. That's not what I wanted.
It seems hard to plot two line with this configuration:
* Line 1 Y-axis data from line1Yvalues range and X-axis data from commonXvalues range.
* Line 2 Y-axis data from line2Yvalues range and X-axis data from commonXvalues range.
Here is yet again the corrected version of the method:
public void TestAddChart(XlChartType type, System.Drawing.Point location, Size size)
{
ChartObjects chartObjects = (ChartObjects)workSheet.ChartObjects(Type.Missing);
ChartObject chartObject = chartObjects.Add(location.X, location.Y, size.Width, size.Height);
Chart chart = chartObject.Chart;
Range line1Yvalues = workSheet.get_Range("A1", "A5");
Range line2Yvalues = workSheet.get_Range("B1", "B5");
Range commonXvalues = workSheet.get_Range("C1", "C5");
chart.SetSourceData(line1Yvalues, XlRowCol.xlRows);
chart.SetSourceData(line2Yvalues, XlRowCol.xlRows);
chart.SetSourceData(commonXvalues, XlRowCol.xlColumns);
chart.ChartType = type;
}
|
|
|
|
|
I stress again that I have never done this myself, so anything I say is pure guesswork.
If the line you get is definitely from column 'C' and that is the only one set to xlColumns then if it was me I would experiment by changing each of the SetSourceData lines....
first line xlColumns other two xlRows, first two lines xlColumns..... etc. until you have a firm grasp of how doing so affects the output.
[Edit]
It has just occurred to me that your third SetSourceData line should not be there at all. After all commonXvalues contains values that should be displayed on the X axis, not data points. Maybe there is another method of chart to set these values chart.XLegend or something.
[/Edit]
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
|
|
|
|
|
I have been trying some test, switching the XlRowCol value for both line1Yvalues and line2Yvalues in the SetSourceData() and removing one of SetSourceData() method call, this is my conclusion:
1) The XlRowCol should be set to xlColumns (don't ask me why)
2) If I only have one SetSourceData() method call, the graph turns out to be just what I want for one line. But, I have not specified what the line's X-axis data is taken from. That is automatically filled in by Excel and I don't want that.
This mean that this solution don't work for multiple lines. Is there any other solution?
|
|
|
|
|
Take a look at Simple Column Chart Generator[^] to see if it gives any clues. I realize that it is a Column Chart but I suspect that changing it to a Line Chart will be the least of your problems.
BTW: I found the link by Googling on chart.setdatasource, so if the link above is not useful give google a go.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
|
|
|
|
|
|
Firstly, your link takes you here - to the first page in C# questions, rather than to your earlier message. Out of politeness, fix that (use Edit on your original post).
Secondly, the link takes you to a whole mess of code, and several answers from Luc - over a week ago. As a result, the code you are talking about is unlikely to be the same as that you posted. Post an abstract of your code, showing only the painting-a-rectangle bit, formatted with <pre>...</pre> tags, and we will see if we can work out what your problem is!
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
ok. I will post my rectangle code here...
In my previous post I have solved my problem by making picture box size or bitmap size to image size (Image I load).
now i like to draw multiple rectangle on bitmap. how can i draw. I tried using array in rectangle. but i get error as "Object reference not set to an instance of an object." (Null reference Exception was unhandled).
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (mybitmap == null)
{
mybitmap = new Bitmap(sz.Width, sz.Height);
}
rect[count] = new Rectangle(e.X, e.Y, 0, 0);
this.Invalidate();
if (stayToolStripMenuItem.Checked == true)
{
switch (e.Button)
{
case MouseButtons.Left:
{
rect[count] = new Rectangle(rect[count].Left, rect[count].Top, e.X - rect[count].Left, e.Y - rect[count].Top);
pictureBox1.Invalidate();
break;
}
count++;
}
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
if (mybitmap == null)
{
return;
}
using (g = Graphics.FromImage(mybitmap))
{
using (Pen pen = new Pen(Color.Red, 2))
{
g.Clear(Color.Transparent);
e.Graphics.DrawRectangle(pen, rect[count]);
label1.Top = rect[count].Top; label1.Left = rect[count].Left; label1.Width = rect[count].Width;
label1.Height = rect[count].Height;
if (label1.TextAlign == ContentAlignment.TopLeft)
{
e.Graphics.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), rect[count]);
g.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), rect[count]);
g.DrawRectangle(pen, rect[count]);
}
}
|
|
|
|
|
Ok, loads of things. Lets start with the simple stuff. Ignoring your drawing for the moment, your rectangle array has probably got problems. I can't see where you have defined it, or count, but I see nowhere where you change the value of count, so you would be over-writing the same rectangle. Unless you know in advance how many times teh use is going to click on your picture box, don't use an array - they are a fixed size. Use a List<Rectangle> instead:
List<Rectangle> rectangles = new List<Rectangle>();
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
rectangles.Add(new Rectangle(0, 0, e.X, e.Y));
} This adds a new rectangle to your list every time the user clicks the picture box. Note that I have changed the parameters for the rectangle to give it a width and height, which yours lacked!
Changing to a List will almost certainly get rid of your "Object reference not set..." error.
The next bit involves your drawing: You draw in the PictureBox.Paint event, but this may be a problem all on it's own. Your bitmap is persistent: changes you make to it are not lost. The paint event is there because the screen is not persistent - whenever it is invalidated, it must be re-drawn. When you draw on your bitmap in the Paint event, you are drawing again, and again, and again on the same bitmap that you drew on last time! Am I also right in thinking that your PictureBox control also displays the bitmap? If so, why are you handlign Paint yourself? If not, why are you using a PictureBox?
Instead, draw onto your bitmap when you add the rectangle to the list. If you need to handle the Paint event, either draw each rectangle onto the graphics context provided (e.Graphics) using a foreach loop to process each Rectangle in the list, or draw the bitmap to the graphics context provided.
Well done on putting using blocks round your Graphics and Pen items though!
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|