|
Hello,
I have to import dbf database files to my c# application. what is the best way to do that? I use vs2005 express and I have also the sqlexpress
Regards
Hansjörg
|
|
|
|
|
I want to get the primary Key of the selected row in DataGridView when double clicked ...
You know in .net 1.1 we had a datagrid with DataKeyField property to save a special field of table like primary key field. but in DataGrid 2.0 or in DataGridView 2.0 this property disapeared...
Now! how can I get PK when a row selected ?
www.behzadi.net
-- modified at 10:43 Thursday 6th April, 2006
|
|
|
|
|
hi
Use the DataKeyNames property to specify the field or fields that represent the primary key of the data source.
u can use this
|
|
|
|
|
Hi there, I hope someone can help me regarding a windows form program.
I would like the user be able to press a button on the form and then an OpenFileDialog box opens, the user then selects a file that is at a certain location (similar to attaching a file when sending email). Then he presses another button on the form and a SaveFileDialog box appears letting the user select where he wants to save/move the file he just selected. How is this done? Can someone please help me?
I hope I have explained this clearly enough.
Thanks,
F
|
|
|
|
|
Get the path of the file opened from the OpenFileDialog via openFileDialog.FileName. Store that file name in a variable, let's call it oldPath. In the save file dialog, after the user clicks OK, simply call System.IO.File.Move(oldPath, mySaveFileDialog.FileName);
|
|
|
|
|
Thanks for your answer.
I see that File.Move takes as a parameter the source filename but what about the path? Does the dialog box take care of the path, where to save the file?
Thanks again for your help.
F
|
|
|
|
|
When you retrieve the FileName from either the OpenFileDialog or the SaveFileDialog, it should contain both the path and file name, I believe.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: How 'bout a little guitar now?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Hello,
I'm building an upload tool in c# but I only want to show de directories where the user has access to from the computer he is sitting on.
I made a script that lists al the directories in a treeview, but it gives an error when it comes to a directory where the user had no access to.
(ex. c:/documents and setting/administrator)
Here a sample of my script
private void FillDirectoryTree(TreeView tvw)
{
tvw.Nodes.Clear();
string[] strDrives = Environment.GetLogicalDrives();
foreach (string rootDirName in strDrives)
{
MessageBox.Show(rootDirName);
if(rootDirName == "C:\\")
{
try
{
DirectoryInfo dir = new DirectoryInfo(rootDirName);
dir.GetDirectories();
TreeNode ndRoot = new TreeNode(rootDirName);
tvw.Nodes.Add(ndRoot);
GetSubDirectoryNodes(ndRoot, ndRoot.Text, 1);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
Application.DoEvents();
}
private void GetSubDirectoryNodes(TreeNode parentNode, string fullName, int level)
{
DirectoryInfo dir = new DirectoryInfo(fullName);
DirectoryInfo[] dirSubs = dir.GetDirectories();
foreach (DirectoryInfo dirSub in dirSubs)
{
if ((dirSub.Attributes & FileAttributes.Hidden) != 0)
{
continue;
}
TreeNode subNode = new TreeNode(dirSub.Name);
parentNode.Nodes.Add(subNode);
if (level < MaxLevel)
{
GetSubDirectoryNodes(subNode, dirSub.FullName, level + 1);
}
}
}
private void tvDestFiles_AfterSelect(object sender, TreeViewEventArgs e)
{
txtTargetDir.Text = tvDestFiles.SelectedNode.FullPath;
}
private void btnUploadFiles_Click(object sender, EventArgs e)
{
List<fileinfo> fileList = GetFileList();
foreach (FileInfo file in fileList)
{
try
{
file.CopyTo(txtTargetDir.Text + "\\" + file.Name, true);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Application.DoEvents();
}
private List<fileinfo> GetFileList()
{
List<string> fileNames = new List<string>();
foreach (TreeNode theNode in tvSourceFiles.Nodes)
{
GetCheckedFiles(theNode, fileNames);
}
List<fileinfo> fileList = new List<fileinfo>();
foreach (string fileName in fileNames)
{
FileInfo file = new FileInfo(fileName);
if (file.Exists)
{
fileList.Add(file);
}
}
return fileList;
}
private void GetCheckedFiles(TreeNode node, List<string> fileNames)
{
if (node.Nodes.Count == 0)
{
if (node.Checked)
{
string fullPath = GetParentString(node);
fileNames.Add(fullPath);
}
}
else
{
foreach (TreeNode n in node.Nodes)
{
GetCheckedFiles(n, fileNames);
}
}
}
private string GetParentString(TreeNode node)
{
if (node.Parent == null)
{
return node.Text;
}
else
{
return GetParentString(node.Parent) + node.Text + (node.Nodes.Count == 0 ? "" : "\\");
}
}
Some help please
Thx
wistiti 5
|
|
|
|
|
You should be able to catch the System.UnauthorizedAccessException to "skip" a directory you don't have access to.
|
|
|
|
|
Hello,
I have a treeview control, that I populate from a table. I have a column that specifies the sort order of the nodes. However when I use insert method, it seems that the treeview control resorts the nodes, and re-indexes the nodes on every insert.
So: If I insert the Node1 with index 3, after insert it's index will become 0.
Is there a way of avoiding that? I am using .NET 2.0 and I can't find the TreeView.Sorted property.
Thank you.
-- modified at 9:44 Thursday 6th April, 2006
|
|
|
|
|
You can't insert at index 3 if there aren't at least 2 nodes yet.
What you should do is select your data from your table ordered by the sort order in the table. So if your table is called Foo, and the Sort Order column is called SortOrder, you would do something like:
SELECT * FROM Foo ORDERBY SortOrder
The results will then come back to you in ascending order (i.e. 0, 1, 2, ...). From there, you can just call treeView.Nodes.Add; no need to deal with insertion since they're all in the correct order already.
|
|
|
|
|
Thank you
I thought of that before, but I thought maybe there was other ways to control the node sorting. But I guess there is only one way to go about it. I actually tried IComparer handler, but it did not work out as I wanted to.
Thanks again.
|
|
|
|
|
There is another way, but it requires more memory allocation and more CPU processing on the client end:
When you read data back from the table, insert it into a System.Collections.Generic.SortedList, where the sorted list's keys are the sort order integers. From there, you should be able to iterate through the sorted list and insert a tree node at each index, as the iterating through the sorted list will be ordered in ascending order based on the sort order (i.e. 0, 1, 2, etc.)
But I would recommend you simply do an ORDERBY on your table to get the results back in the correct order to begin with. Easier that way and less overhead.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: How 'bout a little guitar now?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Please tell me some websites for programming windows form in .NET
Thanks to kind people.
|
|
|
|
|
codeproject is not enough? try csharpcorner.com, csharphelp.com... use google :]
|
|
|
|
|
Try a look around here:
http://www.windowsforms.com
I'm in the high-fidelity first class traveling set.
And I think I need a Lear jet.
|
|
|
|
|
Could you give me title some books to design form like the image at the frontpage of www.windowsforms.net
Thanks a lot
|
|
|
|
|
|
Could you give me the best books in that ?
Thank you very much
|
|
|
|
|
Just about anything by Sells, Richter, Box, and Griffiths should suffice. I'd recommend Ian Griffith's .NET Windows Forms in a Nutshell, but that's just my opinion.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: How 'bout a little guitar now?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
I have Use a Win32-API in a C# project.
I want to use P/Invoke to call the functions from the dll, in my WinForm.
Question 1
Is it possible to define the signature of all the methods I need in a seperate class, create the object of that class in my Form and use it to access the methods I need.
Questions 2
Do I have define the other stucts and variables or the methods alone.
Can any1 plz help me out
-- modified at 9:04 Thursday 6th April, 2006
|
|
|
|
|
1. You wouldn't create an object of that class to access the methods since all of these methods are static. You would need a separate class like this:
public class Win32
{
[DllImport("user32.dll")]
public static extern int SendMessage( IntPtr hwnd, uint uMsg, IntPtr wParam, IntPtr lParam);
}
2. I am not sure what you mean, but if there are some Win32 calls that use structures then you would have to define those in your code.
I hope this helps.
Deus caritas est
|
|
|
|
|
thanks buddy i'll try to clear mi question
1. I want to keep the api reference calls separete from the winform in my winform, thats why i wanted to call the api methods indirectly
Method call Method Call
My WinForm ------------------> My Class --------------->API
So I would call the methods of MyCalss through its object created in My WinForm. Which inturn calls the appropriate methods from the API.
Tell me If I am heading in the wrong direction.
2. I mean that If the methods of api has params (defined in structs in api).
o O º(`'·.,(`'·., ☆,.·''),.·'')º O o°
»·'"`»* *☆ t4ure4n ☆* *«·'"`«
°o O º(,.·''(,.·'' ☆`'·.,)`'·.,)º O o°
-- modified at 6:20 Friday 7th April, 2006
|
|
|
|
|
Here is what it will look like:
class MyForm : Form
{
protected override void OnLoad()
{
Win32.MessageBox( this.Handle, "Text here", "Caption", 0 );
}
}
class Win32
{
[DllImport("user32.dll")]
public static extern int MessageBox(IntPtr hwnd, [MarshalAs(UnmanagedType.LPTStr)] string msg, [MarsalAs(UnmanagedType.LPTStr)] string caption, int flags);
}
I hope this helps.
Deus caritas est
|
|
|
|
|
|