|
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.
|
|
|
|
|
private async void FindAllBTN_Click(object sender, EventArgs e)
{
progressBar.Minimum = 0;
if (!isRunning)
{
isRunning = true; <<============ I missed this line, Now it works smouthly
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;
}
see above
I'am very thank you for your eforts to help
|
|
|
|
|
I have an existing code base, which we catch exceptions etc.
Does anyone know if there is a way to list all the exceptions that either the code catches or raises so that I can do a review? reason for the review is the result of a pen test, which they flagged that the responses had too much details inside the exception.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
modified 17-Jan-22 8:37am.
|
|
|
|
|
I'd probably use Notepad++ to do a File Content search for "Catch" and "Throw" on my project folder
|
|
|
|
|
Thanks, was wondering there was a clever way to do this but sadly not.
Thanks for you time
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
VS can do a "Find in files" across a whole project or solution, and that can be a regex. So "\scatch\s" and "\sthrow\s" would find and list them all in the "Find" pane (which can be copied to the clipboard) or double clicked to go to each in turn)
"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, was wondering there was a clever way to do this but sadly not.
Thanks for you time
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
In my experience the most interesting exceptions are the ones we do not throw or catch ourselves, but we get for free by calling some CLR class. Example: Image.FromFile() can throw an OutOfMemoryException when the file's format isn't recognized! Now how do you make sure your code base handles that properly???
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.
|
|
|
|
|
Thanks Luc,
the reason I was asking is that we have a task from the security team who pen tested a platform we released. to review all the messages that are returned by the platform to mobile devices.
this main api in this platform is large and requires a lot of reading and was wondering if I could in a automated fashion return on the exceptions rather than used human eye.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Log them in FirstChanceException. Have a white / black dictionary / list as you work through them.
Quote: This event is only a notification. Handling this event does not handle the exception or affect subsequent exception handling in any way. After the event has been raised and event handlers have been invoked, the common language runtime (CLR) begins to search for a handler for the exception. FirstChanceException provides the application domain with a first chance to examine any managed exception.
AppDomain.FirstChanceException Event (System) | Microsoft Docs
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|