|
This is all basic stuff. Have you considered buying a book on C#? You might find your work progresses faster. Jon Skeet's book is widely considered a good choice.
|
|
|
|
|
In a C# 2008 /2010 application, I need to write code to acomplish the following tasks:
1. Will search a file directory path to locate a specified folder. The specfic folder name will look like: Company name1(trannumber). Basically the folder structure name is the company name, with paraenthesis with a transction number.
2. Within the selected folder, I need to pick the excel files where the names look like the following:
company1summ.xlsx,
company2summ.xlsx.
Basically I need to pick the summ.xlsx part of the file name. I do not want the company name. I do not want to pick the *.xlsx only since there will be other .xlsx files in the directory that I do not need to work with.
Thus can you tell me how to accomplish my goal and/or point me to a reference I can use to help me accomplish this task?
|
|
|
|
|
|
Hi,
I have gridPatients_DoubleClick in my application which has a code inside it.
I want to use the same code in gridPatients_KeyDown
using C#, How can I call the gridPatients_DoubleClick from gridPatients_KeyDown?
|
|
|
|
|
Try the following approach - anything else is unclean:
private void gridPatients_DoubleClick(object sender, System.EventArgs e)
{
DoStuff();
}
private void gridPatients_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
DoStuff();
}
private void DoStuff()
{
}
|
|
|
|
|
Quite right. Although the key down handler should be
private void gridPatients_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(the key was the one you wanted)
DoStuff();
}
|
|
|
|
|
In a C# 2008 application, I have the following linq to sql statement setup so far.
eDataContext eData = new eDataContext();
var eSelect = (from iw in eData.Ibooks
join ip in etData.IPack on iw.P_ID equals ip.P_ID
join eTrack in eData.eRPT_Trans
on ip.TNum equals eTrack.P_ID
where ip.TNum == packageId
select iw).FirstOrDefault();
I want to obtain values from the 3 different tables listed in the statement above
How do I change the linq statement above so that I can obtain data from all three tables?
Thus can you show me how to obtain data from all 3 tables?
|
|
|
|
|
As part of your select statement, you can put any fields from the three tables in there, just as if you were doing a select in SQL. Ex: Select {iw, ip, eTrack}. The best thing would be to use select fields instead of all of the fields from all three tables.
|
|
|
|
|
eDataContext eData = new eDataContext();
var eSelect = (from iw in eData.Ibooks
join ip in etData.IPack on iw.P_ID equals ip.P_ID
join eTrack in eData.eRPT_Trans
on ip.TNum equals eTrack.P_ID
where ip.TNum == packageId
select new
{
iw.P_ID,
ip.P_ID,
eTrack.P_ID
/*
Other fields
*/
}
).FirstOrDefault();
|
|
|
|
|
Hi all,
In my windows form I have many group-boxes with text-boxes.
I am changing the back color of the text-boxes whenever a text-box has or looses focus.
This works OK.
I also want to add a help button in the group-box when a text-box in this group-box has focus,
but my help button is added three times?
This is the code I use:
private void control_Settings()
{
Button buttonHelp = new Button();
buttonHelp.BackColor = System.Drawing.Color.Transparent;
buttonHelp.Image = Properties.Resources.HelpButtonImage;
buttonHelp.Dock = DockStyle.Right;
buttonHelp.Name = "buttonHelp";
buttonHelp.Size = new System.Drawing.Size(25, 25);
buttonHelp.UseVisualStyleBackColor = false;
buttonHelp.Click += new System.EventHandler(this.buttonHelp_Click);
foreach (Control gb in Controls)
{
if (gb is GroupBox)
{
GroupBox grpbx = (GroupBox)gb;
foreach (Control t in grpbx.Controls)
{
TextBox textBox = t as TextBox;
if (textBox != null)
{
textBox.Enter += delegate(object sender, EventArgs eventArgs)
{
((TextBox)sender).BackColor = Color.Gold;
Control pToAd = ((TextBox)sender).Parent;
if(!pToAd.Controls.Contains(buttonHelp))pToAd.Controls.Add(buttonHelp);
};
textBox.Leave += delegate(object sender, EventArgs eventArgs)
{
Control pToRemove = ((TextBox)sender).Parent;
((TextBox)sender).BackColor = Color.White;
pToRemove.Controls.Remove(buttonHelp);
};
}
}
}
}
}
Thanks in advance,
Groover
0200 A9 23
0202 8D 01 80
0205 00
|
|
|
|
|
You must have something strange going on, I just copied your code into a blank winforms project and it worked perfectly.
(I changed some of the naming so I could understand the flow better)
using System;
using System.Drawing;
using System.Windows.Forms;
public partial class FormMain : Form
{
public Form1()
{
InitializeComponent();
ControlSettings();
}
private void ControlSettings()
{
Button buttonHelp = new Button();
buttonHelp.BackColor = System.Drawing.Color.Transparent;
buttonHelp.Dock = DockStyle.Right;
buttonHelp.Name = "buttonHelp";
buttonHelp.Size = new System.Drawing.Size(25, 25);
buttonHelp.UseVisualStyleBackColor = false;
foreach (Control control in Controls)
{
if (control is GroupBox)
{
GroupBox groupBox = (GroupBox)control;
foreach (Control nestedControl in groupBox.Controls)
{
TextBox textBox = nestedControl as TextBox;
if (textBox != null)
{
textBox.Enter += delegate(object sender, EventArgs eventArgs)
{
((TextBox)sender).BackColor = Color.Gold;
Control parent = ((TextBox)sender).Parent;
parent.Controls.Add(buttonHelp);
};
textBox.Leave += delegate(object sender, EventArgs eventArgs)
{
Control parent = ((TextBox)sender).Parent;
((TextBox)sender).BackColor = Color.White;
parent.Controls.Remove(buttonHelp);
};
}
}
}
}
}
}
|
|
|
|
|
Thank You Dave for Your effort,
Knowing there is nothing wrong with my code, I found there is something strange.
ControlSettings()
was also called in:
private void Form1_Resize(object sender, System.EventArgs e)
{
control_Settings();
this.Invalidate();
}
to do some other settings.
If I remove these other settings it is still not working,
If I remove the form resizing it is working OK??
I do not do any resizing so why is the form resize event breaking my control_Settings??
0200 A9 23
0202 8D 01 80
0205 00
|
|
|
|
|
Then remove either control_Settings(); from the resize handler, or stop handling the event if you don't need it.
I added the call only to the constructor as this is the type of code that would normally only be run once.
|
|
|
|
|
I agree with Dave that the code presented works for placing and removing a button. Of course as soon as you try to click on it, the textbox loses focus and the button disappears!
Alan.
|
|
|
|
|
Yeah, I noticed that too - but if that's what the OP wants...
|
|
|
|
|
Hi Alan,
You are absolutely right, but I had to get it working first.
I moved the
buttonHelp.Click += new System.EventHandler(buttonHelp_Click);
to the textBox.enter delegate and modified the textBox.leave to:
textBox.Leave += delegate(object sender, EventArgs eventArgs)
{
Control pToRemove = ((TextBox)sender).Parent;
((TextBox)sender).BackColor = Color.White;
if (!pToRemove.ContainsFocus)
{
pToRemove.Controls.Remove(buttonHelp);
buttonHelp.Click -= new System.EventHandler(this.buttonHelp_Click);
}
};
Return focus to the control is handled in the buttonHelp.Click event handler.
But there is still the question why placing a call to Control_Settings in the Form.resize event,
that is never fired, makes the helpbutton control appear three times??
0200 A9 23
0202 8D 01 80
0205 00
|
|
|
|
|
Just an alternative way of thought.
I would have added the help buttons and made them invisible. When the textbox receives focus I would make them visible, etc...
I think it would be easier to develop, easier to maintain and faster at runtime.
hope this helps.
|
|
|
|
|
How FingerPrint Device uses zkemkeeper.dll to get ID of each user print it's finger in Device
|
|
|
|
|
osama_hagrass wrote: How FingerPrint Device uses zkemkeeper.dll to get ID
We don't know "how" it does that, since we don't have the blueprint of the hardware, nor the source to the dll.
Looking for this[^] tutorial?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
I have a question about the C# 2008 statement listed below:
string[] PkgIDs = rData.details.Where(c => c.batch_id == batchID).Select(c => c.Package_ID).Distinct().ToArray();
foreach (string PkgID in PkgIDs)
{
}
I would want to make certain an exception would not be generated in this situation.
If there is nothing selected for the PKgIDs [] table, do I need to to any check for this condition? If so, what would the check be?
Would you show me what code I would need to add?
|
|
|
|
|
Based on what you've posted so far, there is no exception possible. But, since we can't see the code that declared these types, the details collection, how it's populated, ..., we really couldn't tell you for sure.
But, if the Select returns no ID's, the array will come back empty and the foreach iterating over it won't do anything.
You don't have to change this code at all.
Next time, you might want to try testing the code with test data specifically designed to try and break it.
|
|
|
|
|
sc steinhayse wrote: I would want to make certain an exception would not be generated in this situation
Look up each command in the documentation, see if they CAN throw an exception. For example, the Distinct[^] method does not throw anything, but ToArray[^] might throw an ArgumentNullException .
sc steinhayse wrote: Would you show me what code I would need to add?
None, since you can't handle the exception locally (in this example). Have it propagate to the general exception-handler, and log it there.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
string[] PkgIDs = rData.details.Where(c => c.batch_id == batchID).Select(c => c.Package_ID).Distinct().ToArray();
if(PkgIDs.Count > 0)
{
foreach (string PkgID in PkgIDs)
{
}
}
|
|
|
|
|
Totally unnecessary, foreach can iterate over a zero size collection without any problem.
|
|
|
|
|
Write unit tests for the situations you are worried about and see if the result is correct?
|
|
|
|