|
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid..
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
I want to call SaveChanges in my WPF app. SaveChanges calls AddCompany or UpdateCompany on the server, I DON'T want the UI to hang up. After the save completes, there are other things I need to do.
public override bool SaveChanges()
{
// Validate the data entry
bool isValid = Validate();
if (isValid)
{
// Save Add or Update
var task = Task.Factory.StartNew(() =>
{
if (Company.Id == 0)
{
AppCore.BizObject.AddCompany(Company);
}
else
{
AppCore.BizObject.UpdateCompany(Company);
}
}).ContinueWith(a =>
{
// Do cleanup stuff
});
}
return isValid;
}
This is being called from a Save button. This doesn't feel right. What's the right way to call AddCompany/UpdateCompany asynchronously and then handle the clean up stuff? I'm not sure how to structure the code.
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 13hrs ago.
|
|
|
|
|
Move it to a second thread: I'd suggest a BackgroundWorker as a simple to manage way to do it - it can report progress and completion via Events
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Doesn't that negate the whole purpose of Async/Await?
What I'm trying to understand is the correct way to use Async/Await.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
As already mentioned by Kevin Marois the correct way would be using a worker thread
|
|
|
|
|
I have a list of members (integer numbers):
List<int> emptyRows = new List<int>();
for (int i = 0; i < LastRow+1; i++)
{
if (worksheet.Cells[i, 0].Value.IsEmpty == true)
{
emptyRows.Add(i);
}
}
I want to subtract 1 from all the members (member1 -1, member2 -1, ...).
How can I do this using Linq?
Please guide me by giving an example code.
Thanks.
modified 14hrs ago.
|
|
|
|
|
You can't: for the same reason that you can't use a foreach loop to do it.
Integers are value types: every time you try to use one, you create a copy, there is no reference to it.
If you use a class, you can do it using the ForEach method:
public class foo
{
public int val { get; set; }
}
List<foo> foos = new List<foo>();
for (int i = 0; i < 10; i++)
{
foos.Add(new foo() { val = i });
}
foos.ForEach(f => f.val += 10);
foreach (foo foo in foos)
{
Console.WriteLine(foo.val);
}
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I tried to ask a simplified mode of my problem. Let's explain it. I want to delete empty rows in DevExpress Spreadsheet by code. I tried this:
IWorkbook workbook = spreadsheetControl.Document;
Worksheet worksheet = workbook.Worksheets["Sheet1"];
CellRange range = worksheet.GetUsedRange();
int LastRow = range.BottomRowIndex;
List<int> emptyRows = new List<int>();
for (int i = 0; i < LastRow+1; i++)
{
if (worksheet.Cells[i, 0].Value.IsEmpty == true)
{
emptyRows.Add(i);
}
}
Search:
if (emptyRows.Count >= 1)
{
foreach (var item in emptyRows)
{
worksheet.Rows[item].Delete();
emptyRows.RemoveAt(item);
goto Update;
}
}
Update:
if (emptyRows.Count >= 1)
{
for (int i = 0; i < emptyRows.Count; i++)
{
emptyRows[i] = emptyRows[i]-1;
}
goto Search;
}
In the code above, I try to list empty rows. Then, I delete them based on the created list of Row Indexes. The problem is that each time a row is deleted, other empty row indexes are changed (row-1). I need to find a way to subtract each item in the list by 1 in each iteration. The second solution is to select empty rows and delete them at once. I couldn't use the second way too. Because, I don't know how to do multiple selection by code. Please help me.
|
|
|
|
|
Simple solution: don't go from the beginning to the end, deleted from the end to the beginning.
Run the loop backwards!
And do yourself a massive favour: stop using labels and goto. There is absolutely no need to use them in that code - have you not heard of break in a loop?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
foreach (var item in emptyRows.Reverse<int>())
{
worksheet.Rows[item].Delete();
}
I tried to use Linq namespace for reversing my list. It worked.
Now, I'm trying to use this method for deleting duplicates. 
|
|
|
|
|
You don't need Linq to iterate a list in reverse:
for (int index = emptyRows.Count - 1; index >= 0; index--)
{
int item = emptyRows[index];
worksheet.Rows[item].Delete();
} Using Reverse will take longer and use more memory.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
You cannot use "foreach" to do this. "Foreach" uses an iterator to navigate over the collection. Looking at the documentation for Iterator says you cannot add/remove items to the collection being iterated over else you invalidate the iterator.
You must use an indexer, "for", to remove items from the collection. The best way to do that is to start at the end of the array (collection) and move backwards toward zero.
|
|
|
|
|
Hello,
I have Windows Forms C# desktop app with docked window layout.
Ie. few document window and few tool windows.
In that case I used WeifenLuo.WinFormsUI.Docking library.
My question is what is best way to realize event handling after document content change.
Let's consider case.
We can change content in active document window and we can just change active document window. In both cases tool windows should be refreshed based on active document window content (item selected ie.)
|
|
|
|
|
Hi I have a linq query in the following way where two column names from 2 different tables is same, which is giving me error, can somebody please help me in this? How to resolve with alias names if the names are same from 2 different tables and they are used either in select or in group - thank you so much in advance.
Here is my linq query:
ViolationsUniquePenaltyApplied = (from a in violations
join b in programs on a.ViolationTypeId equals b.ViolationTypeId
join d in branches on b.BranchId equals d.BranchId
join e in programs on a.ViolationSubtypeId equals e.ViolationTypeId into es from e in es.DefaultIfEmpty()
where a.ApplyUniquePenalty == true
group new { a.ViolationSubtypeId, e.ViolationTypeName, a?.ViolationTypeId, b?.ViolationTypeName, b?.ParentViolationId, d?.BranchId, d?.Name, a.PenaltyAssessed, a.ViolationId, a.ViolationNumber }
by new { a?.ViolationTypeId, b?.ViolationTypeName, d?.BranchId, d?.Name, a.ViolationId }
into g
select new
{
ViolationTypeId = g.FirstOrDefault().ViolationTypeId,
ViolationType = g.FirstOrDefault().ViolationTypeName,
ParentViolationType = (g.FirstOrDefault()?.ParentViolationId != null) ? (from e in programs where g.FirstOrDefault()?.ViolationTypeId == e.ParentViolationId select e.ViolationTypeName)?.FirstOrDefault() : g.FirstOrDefault().ViolationTypeName,
BranchId = g.FirstOrDefault().BranchId,
Branch = g.FirstOrDefault().Name,
PenaltyAssessed = g.Sum(pc => pc.PenaltyAssessed),
Cnt = g.Count(),
ViolationNumber = g.FirstOrDefault().ViolationNumber,
CountOrId = (g.Count() == 1) ? g.Count() : g.FirstOrDefault().ViolationId,
PenaltyPerUnit = g.Sum(pc => pc.PenaltyAssessed) / g.Count()
})
|
|
|
|
|
What does the "simple" stand for?
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Assuming the problem is the two ViolationTypeName columns in your group statement - and assuming you actually need to group by both - you'll need to specify a different property name for one or both of them.
group new
{
a.ViolationSubtypeId,
e.ViolationTypeName,
a?.ViolationTypeId,
ViolationTypeName2 = b?.ViolationTypeName,
b?.ParentViolationId,
d?.BranchId,
d?.Name,
a.PenaltyAssessed,
a.ViolationId,
a.ViolationNumber
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
modified yesterday.
|
|
|
|
|
hi,
i like to build a restaurant billing system. i would be using Visual Studio 2019. language would be C#.
my question is regarding printing bills.
what is the easiest 3rd party software I can use with Visual Studio 2019 for printing bills to a thermal printer.
|
|
|
|
|
If you are using Windows, the issue is whether your thermal printer has a driver for Windows. If it does, you print to it like you would print to any other Windows printer.
Note that your code will still have to take certain details into account, such as the narrow width of a page, the length of the "page" (a POS printer typically uses a roll that is of "infinite" length). Any such details should be available in the technical reference manuals of the POS printer(s) that you intend to support, or on the manufacturers' websites.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
Oops! I missed the button ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Just to add to what Daniel has said, start with the manufacturers site or tech support - most will have sample code that should give you a "starter".
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi,
I'm trying to use Devexpress library in my own project. I use PivotGridControl to load an excel data into PivotTable. For a test, I used the following code:
public Form1()
{
ExcelDataSource myExcelSource = new ExcelDataSource();
myExcelSource.FileName = @"C:\Users\Fardin\Desktop\Book1.xlsx";
ExcelWorksheetSettings worksheetSettings = new ExcelWorksheetSettings("Sheet1", "A1:B20");
myExcelSource.SourceOptions = new ExcelSourceOptions(worksheetSettings);
myExcelSource.SourceOptions.SkipEmptyRows = false;
myExcelSource.SourceOptions.UseFirstRowAsHeader = true;
myExcelSource.Fill();
pivotGridControl1.DataSource = myExcelSource;
}
But there is following error in System.NullReferenceException: 'Object reference not set to an instance of an object.'
I upload the whole project package:
https://www.dropbox.com/s/vmokcgu21jqohpo/DXApplication1.rar?dl=0
And for Excel file:
Dropbox - Book1.xlsx - Simplify your life[^]
Please guide me.
modified 5 days ago.
|
|
|
|
|
[Devexpress Forums]=>
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Impossible to answer properly, since you didn't even tell us which line / variable is null .
At a guess, the pivotGridControl1 is initialized in the compiler-generated InitializeComponent method, which you haven't called. Therefore, the field is null , and you get a NullReferenceException on the pivotGridControl1.DataSource = myExcelSource; line.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Just to add to what Richard has said...
When you create a form, all the "heavy lifting" of creating controls, setting form properties, and suchlike is performed for you in the MyFile.Designer.cs file method InitializeComponent , which is why the default Form file always contains a constructor which calls it as the first line of code.
This file is created and maintained by the VS designer and isn't normally edited directly.
If you don't call InitializeComponent when you edit the Form constructor, then no controls or properties are ever created for you, and the variables allocated by the designed for them will remain empty - they will contain the default value for a reference value: null
So when your code tries to use them for anything at all, you will get a null reference error, as you have seen.
To be honest, you should have spotted that yourself, and thirty seconds with the debugger would have put you on the right track pretty much immediately! It's worth getting used to the debugger, it's your best friend and will save you hours of hair pulling frustration!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|