|
I believe the OP just wanted to format a number (double, float, whatever) as a string with a certain number of decimal places. Though that seemed like a specific example of a more general question (how to apply formats to objects when serializing them). See my answer the the OP's question for more info.
|
|
|
|
|
Look into string.Format(). This page shows specifically how to format with a given number of decimal places. Also, if you just need to work with one number (day, a double), you can just use ToString to do the formatting for you:
MessageBox.Show((0.1111233d).ToString("0.000"));
|
|
|
|
|
How would I do something like this
var distinctBooks = query
.GroupBy(x => x.BookID)
.Select(x => x.FirstOrDefault());
to this
List<FillGrid> query = (from b in db.Books
join ba in db.BookAuthors on b.ID equals ba.BookID
join a in db.Authors on ba.AuthorID equals a.ID
join bn in db.BookNumbers on b.ID equals bn.BookID
where a.AuthorFirst == splitstring[1].ToString() && a.AuthorLast == splitstring[0].ToString()
select new FillGrid
{
AuthorID = a.ID,
Author = string.Format("{0} {1}", a.AuthorFirst, a.AuthorLast),
Title = b.Title,
Price = (decimal)b.Price,
BookNumber = bn.SurrogateNumber,
BookID = b.ID,
Count = db.BookNumbers.Count(c => c.BookID == b.ID)
}).ToList();
I keep getting a conversion error...
I also tried taking and doing query.tolist().firstordefault(); still no go any help would be great thanks
|
|
|
|
|
your first query works. should work.
so should the second one.
eventually try
var query = ... instead of List...
what's the splitstring?
|
|
|
|
|
I realize the first and second queries work that's not the issue.
The issue is how do i do the first one using the data from the second one?
Basically i want to use the query's results and only return the distinct ones or the firstordefault()
so basically what I'm trying to do is
public class FillGrid
{
public int AuthorID {get; set;}
public int BookNumber {get;set;}
public int BookID { get; set;}
public int Count {get; set;}
public string Title { get; set; }
public string Author { get; set; }
public decimal Price { get; set; }
public string Keywords { get; set; }
public List<FillGrid>FillTheGrid(string treeviewText,string treeviewTag)
{
List <FillGrid>results = new List<FillGrid>();
........
List<FillGrid> distinctresults = query.GroupBy(i => i.BookID).Select(i => i.FirstOrDefault());
return distinctresults;
</pre>
but i keep getting the following error.
<pre>
Error 1 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<yetagain.DataOperations.FillGrid>' to 'System.Collections.Generic.List<yetagain.DataOperations.FillGrid>'. An explicit conversion exists (are you missing a cast?)
|
|
|
|
|
well thats easy
List<FillGrid> distinctresults = query.GroupBy(i => i.BookID).Select(i => i.FirstOrDefault());
List<FillGrid> distinctresults = query.GroupBy(i => i.BookID).Select(i => i.FirstOrDefault()).ToList();
var distinctresults = query.GroupBy(i => i.BookID).Select(i => i.FirstOrDefault());
A LINQ query returns an IEnumerable by default and it does not get exectuted right away.
Only when you do something with it.
But if you call the .ToList() it will execute it and cache the results.
|
|
|
|
|
yeah i just did that before you replied thanks again
|
|
|
|
|
Hi, I'm working on a c# application using MDI containers, and I wonder if there's a way to move a child without showing it's content while dragging it?
I don't know if I'm being clear with my question, I'm trying to do something as the effect of this performance option:
http://img697.imageshack.us/img697/804/examplet.png
|
|
|
|
|
Please don't repost the same question across different forums.
|
|
|
|
|
one of the simplest possible solutions could be to add a panel in all your forms. keep all your controls inside those panels.
Add a bool property named BeintMoved in the form, and in the setter, change the visible property of the panel.
all you need now is to change this property while the form is being moved.
now, whenever form movement happens, this panel will become invisible and so will all child controls.
|
|
|
|
|
The thing is, I want the child mdi forms to stay in the container's border, so the container doesn't have any scroll bars and all the windows stay on the work area.
I have already did this, but the form flickers as it's moving. If I deactivate that option on windows, it doesn't happen, and the form still stays at the border. I imagine using panels, the form would still flicker.
|
|
|
|
|
I am sorry. I don't understand what you want. I thought you wanted to achieve a performance boost by hiding the content of child forms. In that case my solution does the job.
|
|
|
|
|
I want to prevent my child forms from getting out of the borders of the container, which I already did. Now my problem is, the form flickers whenever the user drags it out of the container, but it still stays inside.
Now I'm trying to do something like when you deactivate the "Show window content while dragging" option (you get a rectangle shadow when you move a window instead of moving the whole window) in the forms, not on the whole system. Or if it could be done with another way, I only want to stop the flicker, it's kind of annoying.
|
|
|
|
|
desto-tj wrote: Now I'm trying to do something like when you deactivate the "Show window content while dragging" option (you get a rectangle shadow when you move a window instead of moving the whole window) in the forms
To achive that you'll have to do one of these:
1) dig into the win32 API.
2) or make a trick like when you/user starts moving the form, hide it(or make it invisible) and
draw a rectangle on your container using the form size and location. When finished(mouse released)
change the location of the form and unhide it or make it visible.
Just some ideas. By the way did you set the DoubleBuffered properties to true to both the container and child forms? If not try it. Maybe it helps.
|
|
|
|
|
Hi all,
I'd been trying to set the focus on the property grid by code but I was not able to do it. Could anyone help me with this problem?
Thanks in advance.
Gustavo.
|
|
|
|
|
This seems to work fine for me:
propertyGrid1.Focus();
If you want to focus on a specific property, you must select it.
|
|
|
|
|
i make program that works on LAN network between two PCs how can i do it through internet
(note: the program has two parts the first one is client and the other is server and both of them TCP/IP)
what IP should i use
|
|
|
|
|
74.125.19.147
Just kidding. I don't understand, what is your question?
|
|
|
|
|
thanks
my program is like chat between two PCs i did it in LAN and the IPs are 123.0.0.1 and 123.0.0.2 for internet what is the IP should i use?
|
|
|
|
|
You have to have the two computers figure out eachother's IP addresses somehow. Typically, this is done by having a server negotiate between them (the server tells each computer what the IP is of the other computer). Since most computers have dynamic IP addresses, that's about the only way to do it. However, if one of your computers is a "server" with a static IP, you can have the other computer connect to that computer, at which point it can tell the server what it's IP address is.
If you just want the IP address of each computer for testing purposes, you can visit http://www.whatismyip.com/ on each computer to get that information. If they are on the same network, you may have problems because they may appear to have the same IP address. I'm not sure how you'd handle that.
|
|
|
|
|
|
I'm not familiar with that (just did a Google search), but it looks like UPnP is meant to discover devices on a given network. Don't think that'd work over the Internet.
|
|
|
|
|
It shouldn't, but he never specified which IP he wants to know where, there are many valid reasons to want to know the WAN IP of the local computer
|
|
|
|
|
thanks a lot
the two computers have dinamic IP but for small time i should have the same IP for that time i want my program works
|
|
|
|
|
sanforjackass wrote: how can i do it through internet
Consider studying ASP.NET. It should not be difficult if you can do a client-server application.
sanforjackass wrote: what IP should i use
A computer recognized IP should work!! Wamuti: Any man can be an island, but islands to need water around them!
Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
|
|
|
|