|
-
Feb 5th, 2007, 02:11 PM
#1
Thread Starter
New Member
Need Help accessing Class Properties in a Windows form
Background
excuse my ignorance i'm getting into CSharp development, have knowledge of vb.
Scenario
I have a class module SFactory.cs where I retrieve data from the database into a script collection using sql adapter and filling it in dataset and returnign back as a script collection.
I have 2 values returned from the stored procedure which are stored as Script.Property1 and Script.Property2 (same for each row from stored proc.)
Situation
I need to access these 2 values in 2 textboxes in my windows form
My windows form code looks like this –
ScriptCollection scripts = SFactory.RetrieveScripts(input1, input2, input3);
this.mygrid.DataSource = scripts;
need to add something like as shown below, but i do not see my properties if i can atleast access one row of scripts collection or of the grid and retrieve would help me.
this.mytext1.text = Convert.ToString(scripts.Property1)
this.mytext2.text = Convert.ToString(scripts.Property2)
or
this.mytext1.text = Convert.ToString(grid.row.1.column(8).text)
this.mytext2.text = Convert.ToString(grid.row.1.column(9).text)
any help is sincerely appreciated.
Thanks.
csharp developer
Last edited by csharpdeveloper; Feb 5th, 2007 at 02:20 PM.
Reason: Phrase better
-
Feb 5th, 2007, 03:08 PM
#2
Hyperactive Member
Re: Need Help accessing Class Properties in a Windows form
I don't know if this will help:
check here
-
Feb 5th, 2007, 03:54 PM
#3
Thread Starter
New Member
Re: Need Help accessing Class Properties in a Windows form
Thanks Jennifer..
i had actually looked at it before posting, but what i want is the reverse of it.
i'll appreciate all your help.
Thanks.
-
Feb 5th, 2007, 04:59 PM
#4
Re: Need Help accessing Class Properties in a Windows form
You've told us that a Script object has properties named Property1 and Property2. You've also told us that the scripts variable refers to a ScriptCollection object, which is presumably a collection of Script objects. ALWAYS relate OOP to the real world. If you had an egg carton full of eggs, would you be able to get the yolk, the white and the shell of the carton? Of course not. You'd have to first get an egg from the carton and get ITS yolk, white and shell. You cannot get properties of a Script object from a ScriptCollection object because they are two completely different things. You must first get a Script object from the ScriptCollection, THEN get ITS properties.
-
Feb 5th, 2007, 07:42 PM
#5
Thread Starter
New Member
Re: Need Help accessing Class Properties in a Windows form
In the above context, can you suggest the actual code syntax
-
Feb 5th, 2007, 08:10 PM
#6
Re: Need Help accessing Class Properties in a Windows form
How would you normally get a Script object from a ScriptCollection?
-
Feb 5th, 2007, 11:16 PM
#7
Thread Starter
New Member
Re: Need Help accessing Class Properties in a Windows form
Thanks..
i tried this and it worked
In Collection file -
-----------------
public int ScriptCountOfPages()
{
int iScriptCountOfPages = 0;
foreach (Script script in this)
{
iScriptCountOfPages = script.TotalPageCount;
break;
}
return iScriptCountOfPages;
}
public int ScriptCountOfItems()
{
int iScriptCountOfItems = 0;
foreach (Script script in this)
{
iScriptCountOfItems = script.TotalItemCount;
break;
}
return iScriptCountOfItems;
}
In Win Form-
-------------
this.txtPageCount.Text = Convert.ToString(scripts.ScriptCountOfPages());
this.txtItemCount.Text = Convert.ToString(scripts.ScriptCountOfItems());
need to test... but looks like it worked !!!
Thanks for everyone who replied.
-
Feb 5th, 2007, 11:54 PM
#8
Re: Need Help accessing Class Properties in a Windows form
Those properties look a bit dodgy. They look like you're just getting the page and item count from the first Script object. Surely you want to sum the page and item count for all Script objects in the collection.
Code:
public int ScriptCountOfPages()
{
int iScriptCountOfPages = 0;
foreach (Script script in this)
{
iScriptCountOfPages += script.TotalPageCount;
}
return iScriptCountOfPages;
}
public int ScriptCountOfItems()
{
int iScriptCountOfItems = 0;
foreach (Script script in this)
{
iScriptCountOfItems += script.TotalItemCount;
}
return iScriptCountOfItems;
}
-
Feb 6th, 2007, 06:11 AM
#9
Hyperactive Member
Re: Need Help accessing Class Properties in a Windows form
That's a nice way of describing OOP, --> the carton of eggs.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|