|
Hello,
I have list checked box has items like "C:\" , "D:\" etc... and each item user can check or not. I need to test if current loop string value (drive) is checked or not in the list box
In addition I want to test "if not" condition for ex like this:
if (drive not in chklist_drives.CheckedItems) continue;
|
|
|
|
|
And?
What have you tried?
Where are you stuck?
What help do you need?
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with - we get no other context for your project.
Imagine this: you go for a drive in the country, but you have a problem with the car. You call the garage, say "it broke" and turn off your phone. How long will you be waiting before the garage arrives with the right bits and tools to fix the car given they don't know what make or model it is, who you are, what happened when it all went wrong, or even where you are?
That's what you've done here. So stop typing as little as possible and try explaining things to people who have no way to access your project!
"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!
|
|
|
|
|
Hold on. I did not that my question is vague . I have a list checked box that has items like "C:\", "D:\" etc...
and I need to check current string value in a loop if that value is checked or not in the list box
What I tried:
I have a loop like this:
foreach (drive in all drives)
{
if (drive not in chklist_drives.CheckedItems) continue;
}
Thats it I dont know how I can implement this if line of code
|
|
|
|
|
As you have discovered, drive not in chklist_drives.CheckedItems is not valid C#.
Assuming this is a Windows Forms CheckedListBox control, the CheckedItems collection provides a Contains method to test whether an item is in the collection:
CheckedListBox.CheckedItemCollection.Contains(Object) Method (System.Windows.Forms) | Microsoft Learn[^]
But you're also going to find that foreach (drive in all drives) is not valid C# either. Perhaps you're looking for the System.IO.DriveInfo.GetDrives method[^]?
foreach (DriveInfo drive in DriveInfo.GetDrives())
{
if (!drive.IsReady) continue;
if (!chklist_drives.CheckedItems.Contains(drive.Name)) continue;
...
} You'll need to adjust that code so that the value you check for in the list matches the value you added to the list in the first place.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks alot. Second if is what I need.
|
|
|
|
|
Now compare that against your original question and it should be obvious why it took you 8 hours to get an answer!
If you give us details we can help a lot quicker!
"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 currently learning how to use Entity Framework Core and I'm trying to create a "more advanced" application divided into multiple projects.
When I was using ADO.NET, I would usually make:
- Project.DatabaseAccess - for managing connection strings,
- Project.Shared - base classes and interfaces (which implement INotifyPropertyChanged)
- for example Project.Customers - models for customer-related stuff and a static class with CRUD methods for them.
Customers would then reference the Shared and DatabaseAccess projects.
When using EfCore, I wanted to achieve similar structure, so:
- Project.DatabaseAccess - managing connection strings, main DbContext
- Project.Shared,
- Project.Customers - models for customer-related stuff and repositories for them (with DbContext provided in the constructor)
The problem with that approach is that Customers reference to the DatabaseAccess (for accessing DbContext), and DatabaseAccess needs to reference to the Customers (because it has DbSet<customer>). Unfortunately, you can't make A<-->B references in the Visual Studio.
What other project structures do you recommend? I know that there is something called CleanArchitecture (Application, Domain, Infrastructure), but it doesn't provide the separation between different spheres of my program (Project.Customers, Project.Planning, Project.Mailing, etc.)
Thank you in advance!
|
|
|
|
|
nwbkn wrote: you can't make A<-->B references in the Visual Studio
You can use interfaces for circular references.
nwbkn wrote: Customers reference to the DatabaseAccess
Your Data API layer accepts DTOs (Data Transfer Object) and returns DTOs. So 'Customer' is a DTO which the CustomerDB class uses. Although you can choose your own names for the classes.
Create Data Transfer Objects (DTOs) | Microsoft Learn[^]
Be very careful about what you put in a DTO. Probably to start out you should have nothing but properties.
|
|
|
|
|
|
jschell wrote: You can use interfaces for circular references. I learn something new every time I visit this website!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
difficulties gives us new challenges and something new to learn.
|
|
|
|
|
Hi,
I have downloaded Visual Studio to write and run C# scripts.
Can I use Microsoft SQL Manager for free to use with C# to create windows database apps?
Or do you suggest another free DB to use? or even another app to run C#?
Basically I want to get my Grand Daughter into programming using C# for, well FREE
Any suggestions and code examples greatly appreciated.
Thanks
|
|
|
|
|
|
Thank you for the quick response, really appreciated
|
|
|
|
|
You're welcome! Good luck with the granddaughter - teaching isn't as easy as some people think ...
"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!
|
|
|
|
|
|
Excellent, Thank you very much
|
|
|
|
|
Note that the current revision (1.1) of the book is more than 17 years old. Don't expect it to cover all the new bells & whistles. A few things have been added since C# version 2.0 and dotNet 3.0, so don't expect to learn enough to understand all the sample code you'll find on the internet today.
Do read the book - Petzold is a top notch technical writer, and most certainly for beginners. Just be prepared to discover that there is a lot more to C#/dotNet today that Petzold couldn't possibly have described in his 2006-2007 book.
Additional comment: Once you are through Petzold, a nice way to learn about more recent additions is to read The history of C#[^] bottom up. The links to the descriptions of each new extension is mostly quite readable!
Religious freedom is the freedom to say that two plus two make five.
|
|
|
|
|
I don't think you meant this message for me.
|
|
|
|
|
It was meant as an extension to your message, an additional comment.
I wasn't prepared for anyone having problems understanding that. In meatspace discussions, I am used to discussion participants expand on each other's contributions, directed to all listeners, not just to the one making the statement expanded upon. I frequently consider network discussions in a similar way: A post is not meant for one specific listener, but for all participants taking part in the discussion.
I'm really sorry for creating this highly undesirable situation; I hope you do not feel terribly offended. That certainly wasn't my intention. I will try to remember in the future that if I add to something that you say, I will not do it as a followup to your post, but wait until someone else makes a followup to your post and rather add my addition to that post, rather than to yours.
Religious freedom is the freedom to say that two plus two make five.
|
|
|
|
|
Sorry, I did not mean to offend you. And your comments are all valid, but I just thought that they would be best posted to the OP, as follow up to what I suggested. Experience (here) tells me that not everyone reads every message in a thread; even though you and I would seem to.
|
|
|
|
|
I retired from a career as a programmer, systems analyst, and SQL Server developer a couple years ago, but had very little experience with C#. Since there is so much info on programming available on the web (thank you Code Project and Stack Overflow), I almost never buy a book on programming. However, I did buy this one and found it valuable:
Head First C# by Andrew Stellman and Jennifer Greene (Don't know them, have nothing to gain by this plug). I have the 4th Ed, there's a 5th coming out in August. I got the PDF version for the publisher's site, but print and kindle are available at Amazon.
After information is presented, they use different kinds of non-conventional exercises designed to help understanding and recall. There are various places on the web where you can preview some chapters and see how they do it.
It is aimed at young programmers just coming up, rather than old farts like me, and may appeal to your granddaughter.
|
|
|
|
|
I'm trying the C# example here:
Changing the Bluetooth Radio Mode | Microsoft Learn
It's referencing BthUtil.dll. I can't find this DLL anywhere. How can I find this?
Thanks
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
Look at the date on the article. It's from 14 years ago and really doesn't apply today.
From what I can tell, BthUtil.dll was part of Windows CE/Mobile, which doesn't exist anymore. It was never part of full-blooded Windows.
You're looking at an article for Windows Mobile!
|
|
|
|
|
I'm not sure that even if you find it, it would be any use to you - BthUtil.dll is part of the Windows Mobile (WM) API which was a derivative of WinCE and which finally died the death back in 2013 - it ran on relatively short lived hardware that certainly isn't being made these days and MS ended support for it back in 2019.
If you are targeting WM deliberately in 2024 then you have to ask yourself "why am I doing this?" as it's going to get increasingly hard to find hardware it will still run on that works!
If you are trying to get something working and didn't realize it was a WM app example you were following then that's your problem, right there!
"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!
|
|
|
|