|
Hello!^^ Im currently trying to take all parametres from an object(they are all strings) and pass onto a single string.
To do this i create 3 lists, the first is where all my objects are added, the second is one i use to add all the parametres from a single object from the first list. The second list only hold the parametres of 1 object at a time. When it has all the parametres of the single object it passes them on to my third and final list(and then clears itself) which is the list i want printed with my stringbuilder. If the objects in my first list only contain 1 string, it works just fine, but when the objects has several parametre values the stringbuilder result of the third list returns this : "System.Collections.Generic.Listxxx" instead of the string item in the list, why?
Here is some of the code:
private List<aTableRow> allTableRows = new List<aTableRow>();
private List<string> singleTableRowValues = new List<string>();
private List<string> finalList = new List<string>();
public void SetTableContent()
{
StringBuilder builder = new StringBuilder();
foreach (var tableRow in allTableRows)
{
singleTableRowValues.Add(tableRow.Product.ToString());
singleTableRowValues.Add(tableRow.Price.ToString());
singleTableRowValues.Add(tableRow.StartDate.ToString());
singleTableRowValues.Add(tableRow.EndDate.ToString());
singleTableRowValues.Add(tableRow.Where.ToString());
singleTableRowValues.Add(tableRow.Note.ToString());
singleTableRowValues.Add(tableRow.TippedBy.ToString());
builder.Append(singleTableRowValues).Append(" - ");
tableContent = builder.ToString();
finalList.Add(tableContent);
singleTableRowValues.Clear();
tableContent = "";
}
foreach (var preparedItem in finalList)
{
builder.Append(singleTableRowValues).Append(" - ");
allTableContent = builder.ToString();
}
}
|
|
|
|
|
..because singleTableRowValues on the line below is a list of strings;
builder.Append(singleTableRowValues).Append(" - ");
If you "toString" that, you get the description as in your title. If you want the values from the list as a single string, I'd recommend the string.Join method.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
In addition to what Eddy said about why you're getting "System.Collections.Generic.List", you've significantly over-complicated this!
Consider something like:
public void SetTableContent()
{
StringBuilder builder = new StringBuilder();
foreach (var tableRow in allTableRows)
{
builder.Append(tableRow.Product.ToString()).Append(" - ");
builder.Append(tableRow.Price.ToString()).Append(" - ");
builder.Append(tableRow.StartDate.ToString()).Append(" - ");
builder.Append(tableRow.EndDate.ToString()).Append(" - ");
builder.Append(tableRow.Where.ToString()).Append(" - ");
builder.Append(tableRow.Note.ToString()).Append(" - ");
builder.AppendLine(tableRow.TippedBy.ToString());
}
allTableContent = builder.ToString();
}
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton
|
|
|
|
|
I want to convert ms word file .docx into .html with image and equation without any paid .dll file.
|
|
|
|
|
The way your question is stated makes it look like you are asking for permission. I'm going to guess that you are looking for a free alternative?
A docx-file is a compressed archive (a zip-file) that you can unpack and read.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I would suggest you using Open xml sdk 2.5 along with Power tool. Trust me, it works everytime.
|
|
|
|
|
If you have DOCX installed on your machine, then you can use Word automation (Interop object) to convert DOCX to HTML
referred assembly 'Microsoft Office 8.0 or 14.0 object library' and you can do it easily
see below link
Microsoft Interop API to convert the .doc, .docx, .dot, .dotx and .xls,.xlsx, .rtf to HTML[^]
OR
you can use OpenXmlSDK to convert it to HTML, PowerTools for Open XML has DOCX to HTML facility
check here[^]
Hope it helps
Find More .Net development tips at : .NET Tips
The only reason people get lost in thought is because it's unfamiliar territory.
|
|
|
|
|
Hi all,
I want in my project(in all forms or object of my project) when user Alt+Shift pressed change text of a label.
please help me.
thanks
|
|
|
|
|
Without Hooking you can't do it automatically in all forms - and that's not a nice idea - hooking is complicated and prone to crashing your system if you make a mistake.
Instead, create a form class called "KeyTrapForm" and derive all your project forms from that.
In KeyTrapForm, override ProcessCmdKey:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if ((keyData & Keys.Modifiers) == (Keys.Shift | Keys.Alt))
{
Console.WriteLine("Both pressed");
}
return true;
}
And do your label stuff.
Do be aware that you will get a lot of passes on the if condition as SHIFT and ALT do autorepeat while held down.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
modified 4-Jul-16 5:27am.
|
|
|
|
|
hi to all
i am new with c#
i tray to sum time in grid view footer
i can sum integer but not time
this is my code
int TotalQuantity = 0;
DateTime dt = new DateTime();
TimeSpan ts();
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TotalQuantity += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Quantity"));
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[0].Text = "TotalQuantity";
e.Row.Cells[0].Font.Bold = true;
e.Row.Cells[1].Text = TotalQuantity.ToString();
e.Row.Cells[1].Font.Bold = true;
e.Row.Cells[2].Text = "TotalTime";
e.Row.Cells[2].Font.Bold = true;
e.Row.Cells[3].Text = dt.ToShortTimeString();
e.Row.Cells[3].Font.Bold = true;
}
}
|
|
|
|
|
Where is the code to calculate the total time, and what values are you using as inputs?
|
|
|
|
|
the code is in the body of the message
|
|
|
|
|
I see two lines that are commented out. What happens when you uncomment them, and why are you converting to int in order to add to a double ? What value is returned from Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Time")); ? What do you expect to see from the line e.Row.Cells[3].Text = dt.ToShortTimeString(); ?
|
|
|
|
|
static int Pow(int x, int y=2)
{
int result = 1;
for (int i = 0; i < y; i++)
{
result *= x;
}
return result;
}
static void Main(string[] args)
{
Console.WriteLine(Pow(6));
Console.WriteLine(Pow(3, 4));
}
So, its to pow Method that's confusing me. If someone can brake it down for me in pseudo code this would be a great help. Thanks
|
|
|
|
|
Why not step through the code in the debugger and examine the variable contents after each line of code?
About the only two things that might confuse you are the method header where you have int y = 2 and the result *= x; line.
The method header sets a default value of 2 for y if the caller doesn't provide a 2nd parameter in the method call.
The result line is a shortcut that expands to
result = result * x;
|
|
|
|
|
Not really much that you can break it down to:
static int Pow(int x, int y=2)
{
int result = 1;
for (int i = 0; i < y; i++)
{
result *= x;
}
return result;
}
|
|
|
|
|
Are you aware that the .NET C# Math library includes a 'Pow function: [^]. Note that this function takes Type 'double arguments, and returns a Type 'double result.
Tutorial on Math.Pow here: [^].
Note that my posting this does not mean that I think the OP working this out for themselves is not a good thing
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
This function calculate nth power of a number (where n is the input given by user), if user has not given any input to application, it default collect it as 2 and calculate its 2nd power.
To calculate power system has multiply same number with itself upto nth time and get the desired value
Find More .Net development tips at : .NET Tips
The only reason people get lost in thought is because it's unfamiliar territory.
|
|
|
|
|
I was trying to load a type using only the type FullName and the Assembly name (unqualified, no version number or hash signature)
It seemed to work for some types....
But some .NET dll does not work, for example:
Type.GetType("System.Drawing.Bitmap,System.Drawing")
returns null (even though my app is currently displaying some WinForm Forms).
Any clue ho how to fix that?
I am also hampering myself by trying to write code that will work on Android, .NET Core, UWP....
[EDIT]
AppDomain.Current.GetAssemblies() works on iOS, Android, .NET desktop!
And .NET Core has something similar..
problem solved!
modified 2-Jul-16 8:21am.
|
|
|
|
|
An overloaded version of the same method allows you to throw an exception if there's an error. It would throw a TypeLoadException[^].
On my machine it is complaining that there is no such type in "ConsoleApplication14". Which is not exactly what I expected
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
My first thought would be that the current Project does not have a valid reference to System.Drawing, but, I am not familiar with the context (UWP ?) you are working with here.
cheers, Bill
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
Hi Bill,
After some testing I gave up on UWP!
This is for the serializer and UWP stream would have been incompatible with the desktop due to the lack of TypeConverter and ISerializable. Even more vexing I can't find the list of loaded assemblies!
So my serializer target is only desktop .NET, iOS, Android and (coming when VS support .NET Core properly) .NET Core.
As a side note, yes it fails, in a windows forms project...
(it being Type.GetType("System.Drawing.Size,System.Drawing") returns null)
Although, FYI, it succeeed if I use the assembly fullname (with version and evidence) which I don't want to...
So for now I just do the code below now, it works!
public static Type GetType(string typeName, string assemblyName)
{
Type result;
var tass = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.GetName().Name == assemblyName);
if (tass != null)
return tass.GetType(typeName);
return null;
}
BTW, did you get the link I send you!?
There is a live version of the serializer now!
(F5 on test project duplicate a winform)
GitHub - superlloyd/Galador.Reflection[^]
|
|
|
|
|
Hello
I have Excel work book with many Rows, how I can split each bunch of rows to a Sheet, by using some of the speedy stuff you guys have.
Please help or I will lose my job.
|
|
|
|
|
Let me think about that ....
(Dump as CSV, split into multiple files, reload, ...)
|
|
|
|
|
You could do it by writing a short Excel macro, something along the lines of:
Sub Macro1()
Rows("1:12").Select
Selection.Cut
Sheets.Add After:=Sheets(Sheets.Count)
Selection.Insert Shift:=xlDown
End Sub
|
|
|
|