|
Guffa wrote: There is no way of knowing for sure what id a record will get until it's created. If you use any method to guess the id (e.g. from the previous records), you might get it right most of the time, but not all the time.
Yes, this is exactly my concern.
How do most apps handle this situation ? I was thinking of making the Work Order TextBox invisible until the user actuallty saves the record.
What do you think ?
Regards,
Luc Morin
|
|
|
|
|
You could make a call to a stored procedure that just creates a blank record in the table. The autoincremented value (ID) gets created, then the SP returns just that ID. You're code can then show a blank edit form so all the details can be filled in. Then the record can be written back to the table with the "checked-out" ID number.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I’m missing something (I’m experienced with C, C++ but not with C#, ASP.NET)...
I want to dynamically create a control/random HTML. Do I have to do it with, for example,
<br />
HtmlTable table1 = new HtmlTable();<br />
table1.Attributes.Add("border", "0");<br />
table1.Attributes.Add("align", "center");<br />
div1.controls.Add(table1);<br />
etc. or can I pass ‘<table border=”0” align=”center”>...</table>’ to something and have it render it?
Rog
-- modified at 14:41 Friday 20th January, 2006
|
|
|
|
|
You don't have to render it if it's already html code. You put it on the page.
Use for an example a placeholder:
<asp:Placeholder id="Arthur" runat="server"/>
Add a literal control containing the html code:
Arthur.Controls.Add(new LiteralControl("<table ... > ... </table>"));
---
b { font-weight: normal; }
|
|
|
|
|
Excellent, thank you.
I already have an 'Arthur' to hang things off. So, to do the dynamic bits, I can just adjust the string or use Arthur.FindControl("x") afterwards to adjust it.
It's these things like not knowing about LiteralControl which are the 'things you don't know you don't know' that make forums like this so worthwhile!
Thanks again.
Rog
|
|
|
|
|
I want to design a program that operate in the following:
click a button--> OpenFileDialog, chose the pic that u want to copy.... If DialogResult.OK --->the selected picture is copied to folder \bin\debug with the name "copied.gif"
Help me, pleaseeeee
|
|
|
|
|
So what's your problem? A picture is a file just like any other so just use File.Copy. Or did you want to convert formats?
|
|
|
|
|
OpenFileDialog openFile = new OpenFileDialog();
openFile.Filter = "Image files|*.tif;*.tiff;*.bmp|All files (*.*)|*.*";
if (openFile.ShowDialog() == DialogResult.OK)
{
File.Copy(openFile.FileName, Application.StartupPath +"\\coped.gif");
}
-- modified at 15:45 Friday 20th January, 2006
|
|
|
|
|
and...
how to create a folder and save my file to that folder???
In OpenFileDialog, filter, how to display in the textbox "File of type" like:
Image File (*.gif;*.jpg;*.bmp)
thanks
|
|
|
|
|
Before saving a file to a particular folder, it is a good practice that you check the folder's existence.
Review the following code:
string MyFolderDir = "C:\\MyFolder\\";
if(!Directory.Exists(MyFolderDir )) // if your folder does not exist
{
Directory.Create(MyFolderDir); // create the folder on the specified directory
}
In the "File of Type" dropdown, you just need to specify the text that would appear and the filter. You can separate them using the "|" character. Like this:
openFile.Filter = "Image File (*.gif;*.jpg;*.bmp)|*.gif;*.jpg;*.bmp";
Microsoft KB and other sites such as this have very good articles about File operations. Try exploring. Enjoy!
-- modified at 9:45 Saturday 21st January, 2006
|
|
|
|
|
I don't understand the Format property on the defaultCellStyle of the column I just added to a dataGridView.
I have it set to Currency with 2 decimals, thus "C2".
I fire up my project, double click in the cell, put in 5 and it doesn't format it to '$5.00'. Why not?
Am I totally missing something?
|
|
|
|
|
Is it possible to make a class in visula basic . net and include it in c# project and make its obect in C# for calling its method
|
|
|
|
|
Sure. The VB.NET class just has to be it's own project. Then, in your C# project, you can set a project (preferrably) reference to the VB.NET project and include the class just like any other pre-written namespace and class in the .NET Framework.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hey everyone...
i've probably missed something very important, and just don't know it.
the reason: i'm trying to populate 2 treeviews from 2 separate threads with separate data in each, both trees are pretty slow to load so i need the threads, else i lock up the ui for about 10sec. I also have to refresh the trees throughout the progress so i've had to build the threads the way i have so i can access it later.
the problem: if i try to invoke both threads in the same form_load block i end up with 2 trees with the same data. if i invoke them separately (comment one or the other out) i have proven that the code works properly for both, so it leads me to believe that i've either done something terribly wrong or i just can't do what i'm trying to do........
any ideas?
here is the code:
Thread PcTree, pclist,EmpTree,emplist;
MethodInvoker CallCompList, CallEmpList;
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
switch (tabControl1.SelectedIndex)
{
case 0:
initializePcTree();
break;
case 4:
initializeEmpTree();
break;
}
}
private void initializePcTree()
{
PcTree = new Thread(new ThreadStart(PopComputerList));
PcTree.IsBackground = true;
PcTree.Name = "PcTree";
PcTree.Start();
}
private void initializeEmpTree()
{
EmpTree = new Thread(new ThreadStart(PopEmpList));
EmpTree.IsBackground = true;
EmpTree.Name = "EmpTree";
EmpTree.Start();
}
private void PopComputerList()
{
CallCompList = new MethodInvoker(CompList);
de = new DirectoryEntry("LDAP://~.com");
ds = new DirectorySearcher(de);
ds.Filter = ("(~)");
this.BeginInvoke(CallCompList);
}
private void PopEmpList()
{
CallEmpList = new MethodInvoker(EmpList);
de = new DirectoryEntry("LDAP://~.com");
ds = new DirectorySearcher(de);
ds.Filter = ("(~)");
this.BeginInvoke(CallEmpList);
}
private void newCompList()
{
CompList();
}
private void newEmpList()
{
EmpList();
}
private void CompList()
{
statusBarPanel1.Text = "Please Wait While We Update the List";
PCmonitorTree.Nodes.Clear();
ParentNode = new TreeNode("TopNode");
PCmonitorTree.Nodes.Add(ParentNode);
foreach(SearchResult sr in ds.FindAll())
{
TreeNode PCnode = new TreeNode();
PCnode.Text = sr.GetDirectoryEntry().Name.Split("=".ToCharArray())[1].ToString();
ParentNode.Nodes.Add(PCnode);
TreeNode PCnode1 = new TreeNode();
PCnode1.Text = "PC - " +sr.GetDirectoryEntry().Name.Split("=".ToCharArray())[1].ToString();
PCnode1.Tag = sr.GetDirectoryEntry().Name.Split("=".ToCharArray())[1].ToString();
PCnode.Nodes.Add(PCnode1);
PCmonitorTree.Sorted = true;
}
PCmonitorTree.ExpandAll();
t = ParentNode;
PCmonitorTree.SelectedNode = t;
statusBarPanel1.Text = "Ready";
}
private void EmpList()
{
statusBarPanel1.Text = "Please Wait While We Update the List";
empTree.Nodes.Clear();
TreeNode ParentNode = new TreeNode("TopNode");
empTree.Nodes.Add(ParentNode);
foreach(SearchResult sr in ds.FindAll())
{
DirectoryEntry DE = sr.GetDirectoryEntry();
TreeNode empnode = new TreeNode();
empnode.Text = sr.GetDirectoryEntry().Name.Split("=".ToCharArray())[1].ToString();
empnode.Tag = sr.GetDirectoryEntry().Name.Split("=".ToCharArray())[1].ToString();
ParentNode.Nodes.Add(empnode);
empTree.ExpandAll();
empTree.Sorted = true;
}
t=ParentNode;
empTree.SelectedNode = t;
statusBarPanel1.Text = "Ready";
}
string Beautiful;
Beautiful = "ignorant";
label1.Text = "The world is full of " + Beautiful +" people.";
Why is common sense such an un-common comodity?
|
|
|
|
|
You cannot call methods on Controls created on another thread. T do this, you have to use the Invoke methods of the Controls.
See this: http://blogs.wwwcoder.com/amachin/archive/2004/12/15/1146.aspx[^]
EDIT: Sorry, misread your article. You are using BeginInvoke, this should work. Anyway, you probably should read the article linked above, it may solve your issue.
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
-- modified at 12:06 Friday 20th January, 2006
|
|
|
|
|
private void PopComputerList()
{
CallCompList = new MethodInvoker(CompList);
de = new DirectoryEntry("LDAP://~.com");
ds = new DirectorySearcher(de);
ds.Filter = ("(~)");
this.BeginInvoke(CallCompList);
}
private void PopEmpList()
{
CallEmpList = new MethodInvoker(EmpList);
de = new DirectoryEntry("LDAP://~.com");
ds = new DirectorySearcher(de);
ds.Filter = ("(~)");
this.BeginInvoke(CallEmpList);
}
Look what you're doing here with the de and ds variables. You're using a class scoped de and ds variables. DON'T! Each thread should create and use it's own set of Directory objects scoped within the methods themselves.
What's happening is that when you launch your first thread, it sets up the de and ds variables to perform a search. While that setup and search is taking place, you launch another thread that, low and behold, reassigns new DirectorySearcher and DirectoryEntry objects to the very same de and ds variables you just setup in your previous thread. Global variables - bad idea...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-- modified at 12:26 Friday 20th January, 2006
|
|
|
|
|
Good point Dave,
I think i picked up that bad habit from those redim-ing vb guys i work with
problem fixed!
string Beautiful;
Beautiful = "ignorant";
label1.Text = "The world is full of " + Beautiful +" people.";
Why is common sense such an un-common comodity?
|
|
|
|
|
I'm calling a method that can throw one of several exceptions:
byte[] ReadFile(string filePath)
{
return File.ReadAllBytes(filePath);
}
When calling this method, do you guys usually catch every possible exception, or just cover it with a single catch block? For example, do you do this:
string errorMessage = null;
try
{
return File.ReadAllBytes(filePath);
}
catch (ArgumentException argumentError)
{
errorMessage = argumentError.Message;
}
catch (ArgumentNullException nullArgumentError)
{
errorMessage = nullArgumentError.Message;
}
catch (PathTooLongException pathError)
{
errorMessage = pathError.Message;
}
catch (DirectoryNotFoundException directoryNotFoundError)
{
errorMessage = directoryNotFoundError.Message;
}
catch (IOException ioError)
{
errorMessage = ioError.Message;
}
catch (UnauthorizedAccessException unauthorizedError)
{
errorMessage = unauthorizedError.Message;
}
catch (FileNotFoundException fileNotFoundError)
{
errorMessage = fileNotFoundError.Message;
}
catch (NotSupportedException notSupportedError)
{
errorMessage = notSupportedError;
}
catch (System.Security.SecurityException securityError)
{
errorMessage = securityError;
}
if(errorMessage != null)
{
MessageBox.Show(errorMessage, ...);
}
Or do you catch it all in a single System.Exception catch block?
try
{
File.ReadAllBytes(filePath);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, ...);
}
Obviously the latter is easier to read and write, but the former is more precise and won't eat up things like system errors (OutOfMemoryException, OverflowException, etc.). Which do you guys suggest?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Little House on the Flickr
Judah Himango
|
|
|
|
|
It depends. For example, when reading a file I'll normally check it exists first, so I a PathTooLongException, DirectoryNotFoundException and FileNotFound are really things I should not be getting, so they'd be covered in a catch all (if at all at that point in the code). Specific things that I can't check for in advance would be in specific blocks.
On the whole I find that exceptions propogate up a couple of method calls in the stack before I actually handle them because often at the point the exception occurs I am not able to handle it so I allow it to propogate up until I can do something about it.
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
Or in case of IO operation it would be better to do:
catch (IOException ex)
{
.. io error occured. PathTooLongException and all other IO related inherit from IOException
}
catch (Exception ex)
{
.. all other unexpected errors
}
|
|
|
|
|
My example was simplified; my real code has the error propagating up a ways until it gets to the UI as well.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Little House on the Flickr
Judah Himango
|
|
|
|
|
I use selected row data of dataGrid to load data into textboxes
When I select the first row of the dataGrid no data is loaded into the textboxes
But when I select any other row, it’s data is loaded to the textboxes, then the first row can be loaed too...!!!!?
If any one knows the reason why the first row don't load until i select any other row at first, I’ll be grateful
|
|
|
|
|
try posting your code so we can determine what is going on.
|
|
|
|
|
How are you loading the data into the textboxes? If you're handling the rowEnter event, I don't believe its raised on the form/page load. Try going to any other row, then back to the first and see if it loads. If that's so, you may have to either just manually enter the data into the columns the first time, or use a different event.
As another option, look into databinding. There are a couple WONDERFUL articles on it here at codeproject that you can search for.
|
|
|
|
|