|
hy everyone!
i was asked to do the following:
i do have an access database which contains a list of account infos. the view looks like this:
acc_id subacc_id acc_name acc_child
the first column contains an index number, the second one is either 0 or an acc_id number (if 0 then it is a parent account, otherwise it is a child account of the parent account, which number is found in the subacc_id). the third filed is the name of the account. and the last one is a counter of how many children are available for the parent account.
what i want to do now:
i want to create a (hierarchical) treeview of this situation. so when it is a parent then it is layer 1, if it is a child then it will be located in layer 2 (so child to the refered parent). on the other hand i do also want to insert the infos of the selected element in some outputfield, meaning the columns of the selected element.
my problem is, i did a lot of c# programming, but i have never done this before. the user interface is quit simple but it has to be filled as well.
so to summarize what i want to do:
1) enter the elements out of the database (row by row) in a (hierarchical) tree view (with parent nodes and child nodes)
2) when an element in the treeview is selected then the infos (which acc_id, which childacc_id, which acc_name and the number of children) have to be displayed in some textfields.
could someone help me out of this please?
by the way: is the collapsing and expanding of the treeview done automatically or do i have to code this as well.
thanks again for your help.
stephan.
|
|
|
|
|
Have you tried searching i) CodeProject ii) MSDN documentation iii) Google for information?
The scenario you describe is quite common; there will be plenty of examples on the web to populate a TreeView control. I suggest you do some research, attempt to solve the problem yourself and post back if you encounter any specific difficulties.
Paul Marfleet
|
|
|
|
|
i already did but it confused me more than it helped
i already had a look at codeproject and google, but it didn't really help me.
well to add the infos in the textboxes is very simple. and i guess to add a new node will be as well, but my number one problem is: how do i read from the database, how do i access it? do i have to access it like a textfile or am i able to address the fields? i included the source to my project, so the first step is done ...
well i will try to find out some more details, but if someone could provide me some further infos as well this would really help. (maybe even a link to a page which describes my problem). because all the things i found didn't work or help me so far.
|
|
|
|
|
This article[^] shows you how to fetch data from an MS Access database using C#. It should be straightforward to modify the example to populate a TreeView control.
Paul Marfleet
|
|
|
|
|
Iam using two forms in a windows appln. How can I access the control of the second form from the first form.
Thank you
|
|
|
|
|
2 options really.
1) Expose the whole control as a property of form 2.
on form2:
public TextBox TextBox
{
get{ return this.textBox; }
}
then in form1:
Form2 form2 = new Form2();<br />
form2.TextBox.Text = "Hello World";
2) Expose just that functionality that you need, without exposing the whole control (this way is arguably preferable)
on form2:
public string SomeTextBoxInfo
{
get{ return this.textBox.Text; }
set{ this.textBox.Text = value
}
then in form1:
Form2 form2 = new Form2();<br />
form2.SomeTextBoxInfo = "Hello World";
|
|
|
|
|
Hello,
This[^] is the answere, from Colin!
All the best,
Martin
|
|
|
|
|
Hi,
after created a good serial number generator, and found the way to use my serial with the msi setup project... I'd like to store the serial number (when possible in a file)....
How can I do????
|
|
|
|
|
|
LoL... Sorry!
I didn't get the notification e-mail! It was exactly what I was looking for, but now we decided to go on another philosophy and check the Serial Number every time the program gets started.
Anyway, that helped me a lot finding the answer to my last question.
Life is not short... the problem is only how you organize yourself
|
|
|
|
|
hi i am working on a project under which i have to store a image in access database i know that the data type of the access variable must be ole object
unfortunately i dont have an idea abt storing it. i know that this question is suited for ado.net forum but i hope you guys will help me even a glimps of the c# code will be helpfull
sindhu tiwari
its me sid
|
|
|
|
|
Save the image to a MemoryStream and use the ToArray method to get the data as a byte array. The byte array can be saved in the database field.
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
thanks for the code but at run time a error is thrown saying
""'"Data type mismatch in criteria expression."'''"
if u have any idea abt this error please let me know
regards
sindhu tiwari
its me sid
|
|
|
|
|
sindhutiwari wrote: thanks for the code
I didn't provide any code.
sindhutiwari wrote: at run time a error is thrown saying
""'"Data type mismatch in criteria expression."'''"
That is an error message from the database that tells you that your SQL query is invalid.
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
This should get you started:
private byte[] ConvertImage(Bitmap image, ImageFormat format)
{
if (image == null)
throw new ArgumentNullException("image");
using (MemoryStream ms = new MemoryStream())
{
image.Save(ms, format);
return ms.ToArray();
}
} The ImageFormat parameter just tells you what format the image is that you want to save, e.g. Jpeg or Png.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
thanks for the code but at run time a error is thrown saying
""'"Data type mismatch in criteria expression."'''"
if u have any idea abt this error please let me know
regards
sindhu tiwari
its me sid
|
|
|
|
|
Use the debugger, step through the code and see where the exception is thrown.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
i dont have any idea abt the debugger step if u dont mind plz tell me
its me sid
|
|
|
|
|
sindhutiwari wrote: i dont have any idea abt the debugger step if u dont mind plz tell me
How can you be coding without knowing how to debug? There's a honking great menu in Visual Studio called Debug. Have a look at what it offers you.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
no problem in that.................
its me sid
|
|
|
|
|
My outlook add in is not loading in PC other than development PC.I tried all above points but still didn't succeed
1) Load behaviour is remain 3 after open outlook
2) In CAS add in has full trust rights
3) There is no error while opening outlook from commnad prompt after execute command set VSTO_SUPPRESSDISPLAYALERTS=0
All points that casue of error are OK but still not working
Please help me
Pritesh Patel
|
|
|
|
|
Hi everyone,
i have a treeview and a sqlserver table called companies. with company id, name, adress, and departments. I have the following code to set the company names in the treeviewnodes:
foreach (DataRow mydr in Sql.mydt.Rows)
{
treeView1.Nodes.Add(new TreeNode(mydr["Dep_comp_name"].ToString()));
}
now how can i set the departments(belonged to the company names) as childnodes to the companyname nodes ?
thanx.
|
|
|
|
|
Retain a reference to each TreeNode object that represents a company after it is created. Call the Nodes.Add method of that object for every department in the company.
Paul Marfleet
|
|
|
|
|
hi paul marfleet,
thanx for your response. i m very new in c# and i still don't understnad how to do that. cause one company can have more departments, how can i get those departments and set it to the node of the right company? Can u give me some code?
|
|
|
|
|
I'm not going to do your (home)work for you. If you want to learn C# or programming as a general discipline, you need to practice solving problems. Since my first post, you haven't demonstrated that you have made any further effort to solve the problem yourself.
I will give you some further pointers though.
1. Fetch your data in a fashion that allows you to easily iterate through i) companies ii) departments within companies
2. When iterating through companies, use a nested loop to iterate through the departments for a company.
3. Retain a reference to each company treenode you add to the tree in an object variable. Add your department nodes as children to each company treenode when iterating through departments for a company.
Paul Marfleet
|
|
|
|