Click here to Skip to main content
15,890,609 members
Everything / Programming Languages / C#

C#

C#

Great Reads

by Wonde Tadesse
The other option will be to use Update Panel ASP.NET control as much as possible. It helps to retain the current position on the page whenever a postback happens to the page.
by Alex Pumpet
A simple program for comparing table data from two sources - SQL databases, Excel, CSV or XML-files
by Dr. WPF
.NET 3.5 SP1 is here! It's time to break out your DirectX skills. This article provides the information necessary to get started using a new DirectX interop feature in WPF called D3DImage.
by John Atten
OWIN, Katana and Middleware Pipeline in ASP.NET

Latest Articles

by Fred Song (Melbourne)
A responsive React frontend interacts in real-time with a .NET 8 Minimal API backend to dynamically display and manage state transitions for a simulated traffic light system.
by Coding Notes
In Part 4, we added basic support for the shopping cart, and now we'll enhance and refine that functionality.
by Nicolas DESCARTES
How to implement authentication in Blazor and ASP.NET Core ?
by honey the codewitch
How to validate fields for things like data entry applications.

All Articles

Sort by Updated

C# 

U 2 May 2024 by ras bry
Thank you to all everyone for your support Dave Kreskowiak, OriginalGriff, Pete O'Hanlon My assignment is already finish now. Thank you so much. Image ouput https://drive.google.com/file/d/1P4hCoqVaQc_rdEIPf1nGtv3AwzmMqWw-/view?usp=sharing
U 2 May 2024 by Fred Song (Melbourne)
A responsive React frontend interacts in real-time with a .NET 8 Minimal API backend to dynamically display and manage state transitions for a simulated traffic light system.
N 2 May 2024 by Coding Notes
In Part 4, we added basic support for the shopping cart, and now we'll enhance and refine that functionality.
N 1 May 2024 by Pete O'Hanlon
You already asked a variation of this question here[^] and, as you have more context there, you should continue there. As I explained in my reply to you there, you need to use the index of the row and the index of the cell that you want to change...
N 1 May 2024 by OriginalGriff
OK, first off your image link gives "Access denied" so we can't gain any information from that and we have no idea what "logical error" you might be talking about: we have no access to your code when running with your data, no way to look at your...
N 1 May 2024 by OriginalGriff
Read the error message, it's very clear: JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifying a DeserializeRootElementName. Your JSON data contains two...
N 1 May 2024 by Member 7513082
I am trying to convert json string to xml in c# and parse the data from acctNo and availBal node in the same. But i am getting exception JSON root object has multiple properties. The root object must have a single property in order to create...
N 1 May 2024 by ras bry
I'm tired to fix my logical error in my datagridview, can someone please help me. Here my code. while (dr.Read()) { int id = dr.GetInt32(0); DateTime startBook = dr.GetDateTime(2); ...
N 1 May 2024 by Pete O'Hanlon
Your problem is on this line:dataGridView1(startBook_C, id - 1).Style.BackColor = Color.Blue As you can see, this looks like a method call. Are you trying to do something like this?dataGridView1.Rows[startBook_C].Cells[id-1].Style.BackColor =...
N 1 May 2024 by ras bry
Attention to all, I need your help I'm using c#. The error message said, the datagridview1 cannot be used like a method. Please help me to fix this issue. here's my code. private void ShowSchedule()//show color { string...
N 30 Apr 2024 by OriginalGriff
This isn't a question that makes any real sense as asked: the DataSet class isn't one that you would normally write any source code in - it's a class that is provided by .NET to interface between a data source and the DataTable object it returns....
U 30 Apr 2024 by Aggeliki Asimakopoulou
I have added a DataSet in my C# solution and I added a table adapter from a query and I don't know at all what kind of source code could be written inside a DataSet class and how could it be used. Does it playes a key role for creating crystal...
N 30 Apr 2024 by PauliKK
You might need to adjust the application manifest or compatibility settings in Visual Studio. This includes checking if your app is requiring specific Windows capabilities or if there are manifest declarations that differ in environments that...
N 30 Apr 2024 by glennPattonWork3
Hi All, I have written an 'app' in C# Visual Studio 2022. My dev machine is a Win 11, Version 23H2 Build 22631.3447 I am trying to run on a Win 11, 23H2 OS Build 22631.3447 machine. running the same version of .NET the executable will run on my...
U 29 Apr 2024 by pdoxtader
Just judging from what you've provided, it looks like you're doing all the work on the UI thread, and you're queuing up items via a timer. I suspect that one job isn't completing before another is started (how fast is your timer set to fire?). So...
U 27 Apr 2024 by Graeme_Grant
I asked Google C# capture mouse[^] and found this: Capture or Detect mouse click on or outside Windows Form using C#.NET[^] UPDATE Let us change the Google Search: c# movemouse[^] - there are 126,000+ results. The first result has a couple of...
U 26 Apr 2024 by G Schulz
I have an HookMouseCallback(int nCode, IntPtr wParam, IntPtr lParam) How do I use these out params in UINT SendInput( [in] UINT cInputs, [in] LPINPUT pInputs, [in] int cbSize ); I am also planning on doing this for keystrokes,...
U 26 Apr 2024 by Richard MacCutchan
It is the view that gets sorted not the source table. So you need to capture the DataView object and display the row from there. See DataView.Sort Property (System.Data) | Microsoft Learn[^] for an example.
N 26 Apr 2024 by Andre Oosthuizen
You are accessing the row at index 4, which is the 5th row in the DataTable which is why you get the vale of '150. Datatable indexes start from 0 - Dim size1 As String = table.Rows(3).Item("Size") If you want to sort the DataTable by the...
U 26 Apr 2024 by Member 10974007
Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim table As DataTable = New DataTable("Players") ' Add 2 columns. table.Columns.Add(New DataColumn("Size",...
N 25 Apr 2024 by Pete O'Hanlon
This is too close to providing code that aids in writing key logging software. Over the years, we have had many requests to provide code to people that can be used maliciously. Now, you might have benign intentions, and if it were just you and me...
U 25 Apr 2024 by G Schulz
I am trying to make a simple macro thing, I want it to record messages such as the mouse inputs, but also things like page select. I plan on saving these into a list or array, and then just looping over them and sending to the computer. I am...
N 25 Apr 2024 by Pete O'Hanlon
There are two parts to this problem if you are keeping it simple, and assuming that your datagrid is entirely viewable in one screen. The first thing you need to consider is how to draw a selection rectangle. There's an article here[^] that...
N 25 Apr 2024 by Member 16239100
I want the datagrid rows to be selected using a selection rectangle like we do in win File explorer Can anyone please tell me how to make this kind of behaviour in our own WPF app. Right now i am making a File explorer kind of behaviour using the...
U 24 Apr 2024 by Ignatius Baron Rio
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Data; using System.Windows.Media.Imaging; namespace...
N 24 Apr 2024 by Nicolas DESCARTES
How to implement authentication in Blazor and ASP.NET Core ?
N 24 Apr 2024 by Graeme_Grant
I did a quick Google Search wpf datagrid multiselect dragging with scroll[^] and found this working solution: DataGrid auto scrolling when doing selection - solved[^]
N 24 Apr 2024 by Graeme_Grant
This is a common question so I did a quick Google Search that many solutions for your question: winform trasparent image overlay[^]. Pick one that best suits your needs.
N 24 Apr 2024 by Golden Basim
i want show an image that contains png logo, this image must be transparent as it over another control (Camera Control). What I have tried: I tried this solution but the issue that the Image (in Transparent control) appears in back of the...
N 24 Apr 2024 by GabrieleTronchin
Some years ago, I had to implement an OPC UA Client and server with .NET. Here are some steps from my journey that may help you: - Nuget packages available are not working as expected. Use the source code directly from GitHub. - The first test...
N 24 Apr 2024 by Jens Madsen, Højby
Fixed: To get a pointer to the first char (or whatever), use 'Marshal.UnsafeAddrOfPinnedArrayElement(Buff, 0)' I believe that using GCHandle to pin 'Buff' isn't needed on a local variable, but you'd better check it!;)
N 24 Apr 2024 by Member 16239100
I want a WPF datagrid which can select the rows same as we can do in Win explorer. For the i have implemented some code and need some help in that. Here the autoscroll for up direction is working fine but for downside autoscroll its not working....
N 24 Apr 2024 by honey the codewitch
How to validate fields for things like data entry applications.
N 24 Apr 2024 by Graeme_Grant
Maybe that is not the best way to do what you want. Have a look at the free options in this google search: winform free pdf viewer - Google Search[^]
N 24 Apr 2024 by Golden Basim
MySQL Database contains huge data (more than 5Gb) and more than 300,000 of records in some table. Some Queries require to handle some of fields value before showing it to the user like this query : var pQuery = DB2.sales_main ...
N 24 Apr 2024 by PKlaus17
I did a WinForm application to view PDF files. I use WebView2 of Microsoft and CoreWebView2.Navigate(pdfFile). The PDF - file ist displayed fine, but I have problems if the PDF file has several pages. It shows me the first page and I get...
N 24 Apr 2024 by M-Badger
Assuming that you wish to change which function is called for different joystick inputs based on a configuration file then you could use something like the code shown below. You might want to try a more elegant solution if there are a lot of...
N 23 Apr 2024 by sdecorme
HI, Actually I've made a winform application that read buttons and axis of my joystick. My goal is to have a config file to set input list with functions list. for example I'm using Sharpdx but I can change if needed Clear = buttons1 Left =...
N 23 Apr 2024 by Member 16250042
Not working about js. $(document.ready(function () { $(window).bind('beforeunload', function () { $.ajax({ url: "SignOut.aspx", }); }); }));
N 23 Apr 2024 by Member 14770314
This only addresses code behind code. There is no solution for event handler or command handler that lives in a databound ViewModel. No solution for that. It forces code behind and not View Model implementation, or at least a partial mvvm solution.
U 23 Apr 2024 by Yevgeniy Shunevych
An introduction to Atata C#/.NET web UI test automation full-featured framework based on Selenium WebDriver
N 23 Apr 2024 by M-Badger
I've not tested this but it would appear that the MS interop library version that you are using doesn't know how to convert images into MathML or LaTeX format. So either you need to convert them to MathML or LaTeX in the document before saving...
N 22 Apr 2024 by Member 7920931
Get element clicked in a canvas. myCanvas.MouseLeftButtonDown += OnMouseLeftButtonDown; private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var layer = (Canvas)sender; var element =...
N 22 Apr 2024 by Pete O'Hanlon
It's been a while since I've done this but I'm pretty sure you are going to have to do stream.Seek(0, SeekOrigin.Begin); once you instantiate it.
N 22 Apr 2024 by AAKASH R from Unknown
VLV paginated group search not working in server. What I have tried: I use C# directoryServices to fetch it. when I implemented it I found that it was working find in windows 2022 server and the same was not working in windows 2019 server. It...
N 22 Apr 2024 by OriginalGriff
There are a few problems here. With your existing code, you need to re-think it as the documentation[^] is very clear: Remarks: You must keep the stream open for the lifetime of the Image. Since your stream is created and no reference to it is...
U 22 Apr 2024 by Ravi Bhavnani
After you set the Label controls' text, call Application.DoEvents();.� There's no need to call .Refresh() on the Label controls. Warning: The Form's message pump will respond to all events when executing Application.DoEvents();, including...
U 22 Apr 2024 by sami alhassan
Dear Sirs I am self learning to C# I am doing a project for Assets management I create user control showing two images (QRCode with BarCode) all ok ad these 2 images saved to sql DB by byte.but when I want to display them in the usercontrol only...
N 22 Apr 2024 by Avinash Korat
Here below is my code in which i try to update label controller which is directly placed inside a Form. I want it to be update after every single second. For that i suspend and resume the layout. But still it isn't updating any data on the...
U 22 Apr 2024 by Conduct dotnet
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the...
N 20 Apr 2024 by honey the codewitch
Scraping the web is easy with Visual FA. Here's an example of how.
N 20 Apr 2024 by Graeme_Grant
So the issue is the uniqueness of the key. Using a dynamic object is the cause of your issue. Each object is unique. This is easy to demonstrate. Create two instances of a class with the same values, then do a comparison. You will find that they...
U 20 Apr 2024 by Golden Basim
I need to get the latest purchases cost for every group based on Item , supplier, unit. and synchronization it to another location .. item 1, pack, Jone, ... item 1, pack, Mich, ... item 1, pack, Yasser, ... item 2, pack, Jone, ... item 2,...
N 20 Apr 2024 by Graeme_Grant
Like desktop apps, you should use multiple techniques to capture and handle errors in your app. Blazor is no different. This page lists a number of strategies that you should be using: Handle errors in ASP.NET Core Blazor apps | Microsoft...
N 20 Apr 2024 by Prasad Sathe
Data not loading on page refresh in blazor webassembly standalone app What I have tried: I have created a sample web app in blazor as webassembly standalone app, then I simply published this web app in a local folder and hosted it in the iis as...
U 19 Apr 2024 by Gerardo Gamo
I know this is very OLD, but NOW myself Im struggling with helping a project that of course also is very old, but anyway, as they are using Web forms or ASPX, here is what I have for anyone having the same issue 1. when working with ASPx, I...
U 19 Apr 2024 by Member 14224038
Hello, what is the best way to get previous character in A-Z, i am having some APIs that return character say 'E' & am thinking to write a function that will return me 'D' ( previous charater) is there any direct function in c# that returns...
N 19 Apr 2024 by Pete O'Hanlon
To add to the answers given above. You should never limit your code to just consider the latin alphabet; there are so many cases where you need to consider international users. Fortunately, this is very simple to cater for. In the following...
N 18 Apr 2024 by Richard Deeming
Given a char, you can subtract 1 to get the previous code-point: char input = 'E'; char output = (char)(input - 1); // Contains 'D' You just need to decide what range of characters you want to support, and validate that the input is within...
U 18 Apr 2024 by OriginalGriff
Yes: subtraction ... using System; public class Program { public static void Main() { string str = "Hello World"; foreach (char c in str) { Console.Write((char)(c - 1)); } Console.WriteLine(); } }...
18 Apr 2024 by Test Mail May2023
using System.Text.RegularExpressions; public class RegexStringReplace { public static string? Replace(string input, string rxPtrn, string rxSubPtrn, string value) { // Create a Regex object with the given pattern Regex...
18 Apr 2024 by OriginalGriff
I'm not sure what you mean by "I have no idea how to implement this method." since you clear have implemented it and got exactly what I would expect from that when it runs. So I can only assume that the example you give isn't representative of...
18 Apr 2024 by dzadel
Hello everyone. Let's say I need a C# method with the following signature: static string? Replace(string input, string rxPtrn, string rxSubPtrn, string value); The method replaces, for each input string that matches a regular expression pattern...
17 Apr 2024 by Zijian
Reusable codes for JWT security in business applications
16 Apr 2024 by Mishael Ogo
A look at a simple SQL builder for Dapper
15 Apr 2024 by OriginalGriff
To add to what Dave has said, the session is a Server side construct, not Client - so it's expiration is unrelated to user input unless that input directly causes the Client browser to send (or request) information from the server. Just moving...
15 Apr 2024 by Jo_vb.net
A workaround (not a solution) for improving two of the remaining issues: For private void SelectItemsInRectangle(Rect selectionRect, DataGrid dataGrid, object sender, MouseEventArgs e) you should use the version which was posted here as...
15 Apr 2024 by Dave Kreskowiak
Quote: i set the idle timeout for 2 minutes, ... then the session getting expired in 2 minutes It's doing exactly what you told it to do! You said expire the session in 2 minutes, so the session is expiring in 2 minutes. What did you think was...
15 Apr 2024 by sysproteam123@gmail.com
Hi, I am working on .Net Core 6(MVC) web application, i set the idle timeout for 2 minutes, when i am moving from one page to another page then the session is working correctly, but when i am staying on any particular page and i am moving the...
15 Apr 2024 by Andre Oosthuizen
As Richard mentioned above, you have no code showing how you are going to loop through the mail items. You also need the 'Outlook.Items' and 'Outlook.MailItem' objetcs for it to work properly. Normally I will not show pointers with as little...
15 Apr 2024 by Member 15418280
I want to read email from outlook in excel macro i want to add some filter for fetching email like subject from date etc. What I have tried: I tried condition but not working below is the code. Public Sub CheckEmail_BlueRecruit() '...
15 Apr 2024 by Graeme_Grant
If you are using data binding, like in this article here: Data binding a ListView[^], then the ListView control becomes a view of the data, not the data container itself. Then you only need to show the properties as columns, as required. This...
15 Apr 2024 by Ismael_1999
I need to create a list view with 3 columns, but I need also 2 more columns with related data that should not be viewed. Is there a way to do this? Thank you. I use Microsoft Visual Studio 2022 and this application is in Windows Forms. What I...
14 Apr 2024 by Pete O'Hanlon
As an alternative to Ravi's answer, there is a quick and dirty "hack" that you can use, assuming you are using Windows Forms here. When you add an item into a listview, you are adding an instance of a ListViewItem. This class has a Tag property...
14 Apr 2024 by honey the codewitch
Implementing a simple JSON parser with Visual FA
14 Apr 2024 by M Imran Ansari
In addition to Solution-1, it's advisable to explore further on your own. It's likely that the `lastUpdate` column might contain some null values, triggering exceptions during calculations. You can also try to modify query handle this scenario by...
14 Apr 2024 by Ravi Bhavnani
There's no standard way to do this in Windows Forms. The alternative I use is to manage a ListView's configuration in another object and initialize and populate the ListView appropriately.� See this screenshot as an example:...
13 Apr 2024 by Member 14224038
Hello, need help in adding objects in dictionary, so when there is new object i am adding key & object but struggling with object because i cant cast it or am doing something wrong ? & it already has the key am appending value to list on same...
13 Apr 2024 by SproketCoder
I've been attempting to retrieve a table from the SQL DB based on user inputs, but I'm encountering the following error: "Format of the string does not conform to specification starting at index 0". The query I'm using is "SELECT * FROM...
12 Apr 2024 by OriginalGriff
Your command string is wrong: SELECT * FROM @Tablename WHERE Created_On >= '@StartDate' AND Created_On
12 Apr 2024 by OriginalGriff
Without your data and some idea what the error message is (and the actual data that generates it) we can't help you - and you have to remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type...
12 Apr 2024 by Member 11400059
Hi I have lambda query for get all of my record change in more then 7 days ago. my query is: var result = db.adss.Include(i => i.AdsTpyeFK).Where(i => i.updateFlag == true && i.AdsTpyeFK.name == "gold" && (DateTime.Now - i.lastUpdate).TotalDays...
12 Apr 2024 by Richard Deeming
Further to Pete's excellent answer, you can use the TryGetValue method[^] to avoid the double key lookup of ContainsKey followed by the indexer: if (!uniqueComp.TryGetValue(cmp1[i].name, out List list)) { list = new List(); ...
12 Apr 2024 by Pete O'Hanlon
Your code should look something like this:if (!uniqueComp.ContainsKey(cmp1[i].name)) { uniqueComp.Add(cmp[i].name, new List()); } uniqueComp[cmp[i].name].Add(... whatever the value is ...); Basically, you are testing to see whether you...
11 Apr 2024 by Akram El Assas
Functional Programming in C# through Algebra, Numbers, Euclidean Plane and Fractals
11 Apr 2024 by Andre Oosthuizen
From what I could make out of your code is that your 'SelectItemsInRectangle' method is only considering the visible rows in your DataGrid at the time that you make the selection. When you scroll, new rows become visible, and your selection...
10 Apr 2024 by Jo_vb.net
I think you have to calculate the rectangle position every time when it should move. Perhaps it is simpler to delete the rectangle which is on wrong position and create a new one on calculated position if needed. ...
10 Apr 2024 by Member 16239100
I am attempting to replicate the selection behavior of Windows File Explorer within a WPF DataGrid. Specifically, I aim to implement a selection rectangle that mimics the functionality of File Explorer's selection mechanism. Currently, I have...
10 Apr 2024 by Graeme_Grant
Quote: When Manager clicks either of the link, it hits the endpoint and their response is Captured in Database. To prevent sharing, the only option is for the intended recipient to log back in, then you verify both the account used to sign in...
10 Apr 2024 by Pete O'Hanlon
I'm afraid you need to go back to whoever gave you the requirements and explain this is a monumentally bad idea, and also impossible to implement. If one manager forwards it to another, you can't prevent that, and you can't change the contents of...
10 Apr 2024 by Vaithilingam Alagappan
When User raise a request for Access. User's Manager needs to approve the request through email. The email will have Approve and Reject link as API endpoint URL. i.e., Approve - https://example.com/api/approve, Reject -...
9 Apr 2024 by Pete O'Hanlon
So, what is it that you want to display as an image? The thumbnail that you would see in Windows Explorer? A detailed, scrollable view of the PDF? I'm going to assume that you want the user to actually see the PDF itself here. If this is the...
9 Apr 2024 by PhamLong301
I'm new in C# and I have create a scanner application by C# winform. Now I'm having a problem that when i use treeview for a folder and click in item inside (all items inside are images and pdf file). All image file format display normal in...
9 Apr 2024 by Richard Deeming
Each iteration of your for (int iR = 0; iR
9 Apr 2024 by Aggeliki Asimakopoulou
I have created a back - end application in C# with embedded microsft sql server. I am pretty new to crystal reports and I had created one but in a wrong way and I am trying to correct it. I almost don't remember how I created and I feel bad for...