|
endo funk wrote: Yes; first off IEnumerable was Microsoft implementation of functional programming algebras for a List. It is essentially a monadic data type that encapsulates List; monadic data types are typically designed to conform to a fairly standard set of functional algebras i.e. providing a common API for computations.
Err..no it wasn't.
IEnumerable existed long before linq. It wasn't added to the libraries in any way shape or form to support functional programming.
Now one could make an argument that they should have started from scratch when they did add linq but that is an argument and not a statement of fact.
One could also argue that they should have redid IEnumerable to support linq. However that argument would have been completely wrong since C# was a practical language not a university exercise. Redoing it would have broken the entire existing body of practical work that was using it. And would have been exactly the wrong thing to do for any language when attempting to enhance and not replace that language.
|
|
|
|
|
Extension methods... apparently so obvious that you missed it.
|
|
|
|
|
endo funk wrote: Extension methods... apparently so obvious that you missed it.
Apparently you do not know what you said...
"first off IEnumerable was Microsoft implementation of functional programming algebras for a List. "
And again, no it was not. It existed long before anything associated with functional programming was in the language.
Refutation of that statement has nothing to do with extension methods which were added long after IEnumerable. I can only suppose that you are claiming that they could have used extension methods when implementing linq. Perhaps. But still that has nothing to do with your original incorrect statement.
|
|
|
|
|
Pssst...
Let's review the opening paragraph's of the OP's post.
Quote: Imagine you have bright young student sitting down with you, whom you've introduced to Linq, and generics ... and, they've had no problems mastering 'Select and 'Where, 'Aggregate, etc.
You have introduced them to the use of 'yield return' in a method to return an IEnumerable they can turn into an instance of a collection. They "get that," and get use of yield means they can skip direct assignment to a pre-defined, initialized collection, or, a collection instance reference passed in as an 'out parameter.
And you are trying to explain to them the "deferred iteration/evaluation" aspect of IEnumerable, and the way that enables some advanced practices (function chaining).
To make it a little easier to grasp for those too easily confused by many words, and / or a greater context than just one singled out by one bit of syntax, namely IEnumerable .
The questions were contextual... which apparently you missed completely. Why else would the second question be about deferred evaluation aka lazy evaluation , contextually similar the third question; the fourth question, fifth question, and finally the sixth question.
Contextually it would be rather silly to focus only on the very rudimentary interface definition of IEnumerable when none of the questions related to that... they all were if you missed it related to the behavior of extension methods of IEnumerable .
Ps. if you find the functional programming confusing just say so... as opposed to engaging in an awkward and rather pointless debate; where you clearly had missed the context that was put forward in the OP's post, and similarly the context implied by the questions.
modified 17-Feb-22 20:44pm.
|
|
|
|
|
Hello,
I hope someone can help me on this problem. i have a database (accdb) from access that i want to filter by several comboboxes.
1 st combobox filter row 1 (BaseM)
2nd combobox filters row 2 (Umat) based on the results from the first combobox.
3rd combobox filter row 3 (Gmat) based on combobox 2
etc.
<pre>
private void cmbBaseM_SelectedIndexChanged(object sender, EventArgs e)
{
matTableAdapter.Fill(this.matBaseDataSet.MatBase);
matBaseBindingSource.DataSource = matBaseDataSet.MatBase;
CMBmMat.DataSource = matBaseDataSet.MatBase.Select(US => US.USnumber).Distinct().ToList();
matBaseBindingSource.Filter = "USnumber = " + cmbBaseM.SelectedItem + "";
}
I get an error on the last part
matBaseBindingSource.Filter = "Umat = " + cmbBaseM.SelectedItem + "";
with the message
System.Data.EvaluateException: 'cannot find column [A].'
I have tried so many things that i'm not sure what the way to go is here.
|
|
|
|
|
Try quoting the value, rather than using the value as a pseudo column name e.g.
matBaseBindingSource.Filter = "USnumber = '" + cmbBaseM.SelectedItem + "'";
|
|
|
|
|
Thank you so much that solved the error message, however the method i used does not filter the other combobox. It only fills it with the data from the other row.
Any pointers on how to filter this?
|
|
|
|
|
I think the solution is to use the same method for the SelectedIndex event in all three combo boxes. Then, regardless of which combo box is changed, the same method will fire. Upon firing, the method should construct a Filter string based on all three selections.
Incidentally, you can use interpolated string syntax for easier coding and reading.
matBaseBindingSource.Filter = $"USnumber = '{cmbBaseM.SelectedItem}'";
You can build complex filtering strings when you're using DataSets and DataTables. Check it out.
DataColumn.Expression Property (System.Data) | Microsoft Docs[^]
|
|
|
|
|
It solved the error, but still have troubles with the filtering.
all the examples i find are using SQL i'm using accdb and it seems that this routines don't quite work the same.
|
|
|
|
|
It's true that Access has a limited implementation of SQL, but I don't think you need SQL to do the filtering itself.
If I understand correctly, you have a database with columns BaseM, Umat, and Gmat. You have a DataGridView that displays the rows from this database, and you have combo boxes holding the unique, valid values for each of the mentioned columns. You would like the DataGridView to display only the rows that contain the values selected in the combo boxes.
If that is so, I would load all the rows from the database into the the dataset using SQL (basic select query), and I would then set the binding source's filter to a string that included all three combo box selections. I had mentioned using just one event handler for all three combo boxes. Something like this?
private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
string[] comboSelections =
{
CmbBaseM.SelectedIndex != -1
? $"BaseM = '{CmbBaseM.GetItemText(CmbBaseM.SelectedItem)}'"
: string.Empty,
CmbUmat.SelectedIndex != -1
? $"Umat = '{CmbUmat.GetItemText(CmbUmat.SelectedItem)}'"
: string.Empty,
CmbGmat.SelectedIndex != -1
? $"Gmat = '{CmbGmat.GetItemText(CmbGmat.SelectedItem)}'"
: string.Empty
};
string filter = string.Join(" AND ", comboSelections.Where(s => !string.IsNullOrEmpty(s)));
MyBindingSource.Filter = filter;
} We first create an array with the selected values, and then we join the non-empty selections with "AND."
modified 24-Jan-22 16:50pm.
|
|
|
|
|
Yes, this actually worked. however it does only filter the fist row BaseM, the next row is not filtered i would expect that the
CmbUmat would be reduced to only the ones that are in the same line as the BaseM.
Got it to work by adding the combobox sources in the start of the form. it works now. Thank you for the help
modified 26-Jan-22 8:09am.
|
|
|
|
|
Oh, I had not thought of the case where the selection in one combo box affected the choices offered in the subsequent combo box! Glad you solved it.
|
|
|
|
|
Hey Community,
I got a problem with calling an new process.
I have a WIN-Form, this is locatet in C:\TesterV4\Launcher.exe
I call a Process in C:\TesterV4\Data\Tests\Manufacturer\device.exe
The process is called with:
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = opentest;
psi.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(psi);
When I use relative file paths in device.exe, (e.g. @"Data\anything.pdf") i get for example:
C:\TesterV4\Data\anything.pdf
what I need and what should happen is:
"C:\TesterV4\Data\Tests\Manufacturer\Data\anything.pdf"
is there any reason to start device.exe without any dependency from launcher.exe and its directory?
When I start device.exe directly via double click, everything is working well :/
Thank you for your help.
desperated,
Daniel
|
|
|
|
|
The current working directory when you run Launcher must be one level above Data for the relative path to be valid. But if you start in C:\TesterV4 then Data\Tests\Manufacturer\Data\anything.pdf will not be found because its actual location is further down the directory tree. You should use absolute paths, or preferably use the OpenFileDialog to ensure you get what the user wants.
|
|
|
|
|
To add to what Richard says, you shouldn;t be storing data in folders below that containing the app EXE file - normally this would be under Program Files, and all folders there are protected to reduce virus activity.
See here: Where should I store my data?[^] for some better ideas.
"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!
|
|
|
|
|
Good Day great people. I need help on writing hoe to print my two panels on back and front of a single paper. I have controls on each of the panels. panel1 and panel two. My code is only displaying panel1 not panel two. Can anyone please help.
Thanks
Gbenga Odumosu
|
|
|
|
|
Unfortunately, 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!
We have no idea what your code is doing, what hardware you are using to print your cards, and no way to help you at all given what you have told us.
So start by creating a "minimal app" which tries to do exactly what you want, but with two fixed strings: "FRONT" and "BACK" then show us the code for that and explain what exactly it does that you didn't expect, or doesn't do that you did. Explain what you expected, and what you got.
Help us to help you!
"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!
|
|
|
|
|
 Thanks so much for your quick response
I actually wrote a biometric c# program on windows form
i have no issue on this but now want to use the information in the database to print id card for each record in the database. My program can successfully retrieve the record and put them in the idcard. I put the controls such as textbox and labels in panel1 (front) and panel2 for back card. My small program using printdialogue and printview shows only one panel on printer dialogue view. My problem is that i want it to print the two panels. one in the front and the other in the back. I am using fargo HD5000 Id card printer that has ability to print on both front and back of the card automatically. I am using printing feature for the first time. And I am surely not getting it right. Please help. I would have posted my screen short but I dont no how to attach it
using System;
using System.Drawing;
using System.Windows.Forms;
using Spire.Barcode;
namespace camera2
{
public partial class Form2 : Form
{
Bitmap bitmap;
//
<pre>
public Form2()
{
InitializeComponent();
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
// using System.Drawing.Printing;
e.Graphics.DrawImage(bitmap, 0, 0);
}
private void CaptureScreen()
{
Graphics myGraphics = this.CreateGraphics();
Size s = this.Size;
bitmap = new Bitmap(s.Width, s.Height, myGraphics);
Graphics memoryGraphics = Graphics.FromImage(bitmap);
memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s);
}
private void print_Click(object sender, EventArgs e)
{
PrintDialog pDialog = new PrintDialog();
pDialog.AllowSomePages = true;
if (pDialog.ShowDialog(this) == DialogResult.OK)
// this.printDoc.Print();
{
// Front card panel 1
Panel panel = new Panel();
panel1.Size = new System.Drawing.Size(600,600);
this.Controls.Add(panel);
Graphics grp = panel.CreateGraphics();
Size formSize = this.ClientSize;
bitmap = new Bitmap(formSize.Width, formSize.Height, grp);
grp = Graphics.FromImage(bitmap);
Point panelLocation = PointToScreen(panel.Location);
grp.CopyFromScreen(panelLocation.X, panelLocation.Y, 0, 0, formSize);
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.PrintPreviewControl.Zoom = 1;
printPreviewDialog1.ShowDialog();
// back card panel 2
Panel panel2 = new Panel();
panel2.Size = new System.Drawing.Size(600, 600);
this.Controls.Add(panel);
Graphics grp1 = panel.CreateGraphics();
Size formSize1 = this.ClientSize;
bitmap = new Bitmap(formSize.Width, formSize.Height, grp);
grp1 = Graphics.FromImage(bitmap);
Point panelLocation1 = PointToScreen(panel2.Location);
grp.CopyFromScreen(panelLocation1.X, panelLocation1.Y, 0, 0, formSize1);
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.PrintPreviewControl.Zoom = 1;
printPreviewDialog1.ShowDialog();
}
}
|
|
|
|
|
I can't help you with that - I have no access to that printer, so I couldn't test any solution I might come up with.
I'd suggest that the best place to start is with the manufacturers - they may have an API, sample code, or at the very least tech support who should be able to at least get you started.
"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 don't know your printer, however I would expect you need to create a PrintDocument that holds two pages, with HasMorePages set true for the first (front) and false for the second (back) page. Assuming this is correct, you could test your code on any printer even one that doesn't do duplex.
Also, the PrintPreview class is capable of showing two pages side-by-side. It takes some experimenting as the documentation isn't perfect, but I managed to get something similar working many years ago.
More info could be available in many places, including here (needs a Microsoft account):
How to show multiple pages in PrintPreview control in c#[^]
Luc Pattyn [My Articles]
The Windows 11 "taskbar" is disgusting. It should be at the left of the screen, with real icons, with text, progress, etc. They downgraded my developer PC to a bloody iPhone.
|
|
|
|
|
Printing is one of my weakest points, so I claim no expertise, but I notice that you seem to print twice. Even though your printer prints on both sides of the paper, I'm sure it starts every print job on a new sheet of paper, thus you get two sheets.
Also, how do you create printDocument1 ? I see where you assign it to the preview Document property, but what is in it?
|
|
|
|
|
Hi all
I have an async void btn event
witch start with
ttb.text = tb.text
tb.hide
rtb.show
await method
when I click a button that
do find and highlights matches
I get error
richtextbox editstream reference null
can someone help
thank you
|
|
|
|
|
Copy and paste the RELEVANT code and exact error message. What you've included in your description is useless to diagnose the problem.
|
|
|
|
|
private async void FindAllBTN_Click(object sender, EventArgs e)
{
progressBar.Minimum = 0;
if (!isRunning)
{
OutputTB.Hide();
OutputRTB.Show();
FlipNextAllCKB.Checked = true;
OutputRTB.Text = OutputTB.Text;
FindAllBTN.Text = "Cancel";
FindAllBTN.ForeColor = Color.Red;
Progress<int> prog = new Progress<int>(SetProgress);
m_cancelTokenSource = new CancellationTokenSource();
try
{
await FindAllMatches(searchTB.Text, prog, m_cancelTokenSource.Token);
}
catch (OperationCanceledException)
{
}
finally
{
FindAllBTN.Text = "Find All";
FindAllBTN.ForeColor = Color.Black;
isRunning = false;
m_cancelTokenSource = null;
progressBar.Value = 0;
replaceLTB.Focus();
}
}
else
{
m_cancelTokenSource.Cancel();
}
return;
}
public Task FindAllMatches(string searchString, IProgress<int> prog, CancellationToken ct)
{
return Task.Run(() =>
{
try
{
bool yesno = false;
string source = "";
Regex re;
if (searchString == "")
{
OutputTB.AppendText("\r\nNeed RegEx Expression Input\r\n");
return;
}
try
{
re = new Regex(searchString);
}
catch (ArgumentException e)
{
OutputTB.AppendText("\r\nEx Err " + e.ToString() + "\r\n");
return;
}
source = OutputTB.Text;
if (source == "")
{
OutputTB.AppendText("Need Source Text Input");
return;
}
OutputRTB.SelectionStart = 0;
OutputRTB.SelectionLength = OutputRTB.Text.Length;
OutputRTB.SelectionBackColor = Color.White;
MatchCollection matches = Regex.Matches(OutputRTB.Text, searchString);
progressBar.Maximum = matches.Count;
for(int i = 0; i < matches.Count; i++)
{
prog.Report(i);
if (ct.IsCancellationRequested)
{
OutputRTB.AppendText($"\r\nCanceled at Loop {i}");
OutputRTB.AppendText("\r\n");
throw new OperationCanceledException(ct);
}
OutputRTB.SelectionStart = matches[i].Index;
OutputRTB.SelectionLength = matches[i].Length;
if (yesno)
{
OutputRTB.SelectionBackColor = Color.GreenYellow;
yesno = false;
}
else
{
OutputRTB.SelectionBackColor = Color.Turquoise;
yesno = true;
}
}
}
catch (Exception ex)
{
if(ex.ToString().Contains("OperationCanceledException"))
{
}
else
{
}
}
finally
{
}
}, ct);
}
The async await was taken from this sit
Handling long operations with cancel and progress in C# with async – Cowthulu[^]
************************************************************************
ee the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Windows.Forms.RichTextBox.EditStreamProc(IntPtr dwCookie, IntPtr buf, Int32 cb, Int32& transferred)
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
at System.Windows.Forms.RichTextBox.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
I Appreciate Your Willingness to Help me
Ok Thank you I got it.
modified 20-Jan-22 15:40pm.
|
|
|
|
|
I can't test that code, but at first glance, you cannot touch the OutputTB nor the progressBar from the Task. All method and property access on controls must be done from the startup (UI) thread.
|
|
|
|
|