|
Deart Rudy.
Thanx for your attention.But MyNamespace.MyClass is in a separate dll file and I haven't it at compile time.If I write this code I will receive the following error :
The type or namespace name 'MyNamespace' could not be found (are you missing a using directive or an assembly reference?)
Everything is at Runtime
[ _ Always there is another way _ ]
|
|
|
|
|
This should do the trick:
Assembly asm = Assembly.LoadFrom("MyAssembly.dll");
Type t = asm.GetType("MyNamespace.MyClass");
Object obj = Activator.CreateInstance(t);
PropertyInfo pInfo = t.GetProperty("StructVar");
PropertyInfo pInfo2 = pInfo.PropertyType.GetProperty("IntVar");
pInfo2.SetValue(1, pInfo.GetValue(obj, null), null);
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
www.troschuetz.de
-- modified at 13:33 Sunday 7th May, 2006
|
|
|
|
|
Stefan Troschütz wrote: pInfo2.SetValue(1, pInfo.GetValue(obj, null), null);
That won't work, pInfo.GetValue(...) will return a boxed instance of the struct, so setting it's IntVar property won't affect the original struct. As I suggested in my post below, you can call pInfo.SetValue to set the new struct, but I wonder if there's a better way? Maybe an API function to get the struct by reference? Or is this what the compiler does when you call myClass.StructVar.IntVar = 2 ?
Regards
Senthil
_____________________________
My Blog | My Articles | My Flickr | WinMacro
|
|
|
|
|
Ups, I didn't thought so far and the code snippet was a quick, untested shot Thanks for the correction.
Currently no solution comes to my mind, that's better than yours. Would be interesting to dig a bit deeper into this, when having more time than now.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
www.troschuetz.de
|
|
|
|
|
You simply have to call GetProperty again for IntVar, this time on pInfo.PropertyType . That will get you a reference to IntVar's property info, which you can then use to call SetValue. Just remember to call SetValue on pInfo again, as the struct instance you have is a boxed instance and setting it's member values will not affect the original struct.
object o = Activator.CreateInstance(typeof(MyClass));
PropertyInfo structPropertyInfo = typeof(MyClass).GetProperty("StructVar");
object s = structPropertyInfo.GetValue(o, null);
PropertyInfo intPropertyInfo = structPropertyInfo.PropertyType.GetProperty("IntVar");
intPropertyInfo.SetValue(s, 2, null);
structPropertyInfo.SetValue(o, s, null);
MyClass a = (MyClass)o;
Console.WriteLine(a.StructVar.IntVar);
Regards
Senthil
_____________________________
My Blog | My Articles | My Flickr | WinMacro
|
|
|
|
|
Dear Senthil !
Thanx for your fast reply.The solution you provided worked properly.
King Regards,
Amir.
[ _ Always there is another way _ ]
|
|
|
|
|
i've create a simple access database with a table:
ID (int counter *)
Name (string *)
Surname (string)
Age (int)
Memo (memo)
why if i do this:
...
conn.Open();
OleDbDataAdapter oleDa = new OleDbDataAdapter("Select * from myTable", conn);
OleDbCommand cmdInsert = new OleDbCommand();
cmdInsert.CommandText = "Insert into TableNotes (Name, Memo) Values (?,?)";
cmdInsert.Connection = conn;
cmdInsert.Parameters.Add(new OleDbParameter("Name", OleDbType.VarChar, 20));
cmdInsert.Parameters.Add(new OleDbParameter("Memo", OleDbType.WChar));
cmdInsert.Parameters[0].Value = Name;
cmdInsert.Parameters[1].Value = textBox1.Text;
oleDa.InsertCommand = cmdInsert;
cmdInsert.ExecuteNonQuery();
i get error in "insert into query"? if i try to insert just Name it works!
|
|
|
|
|
try to change the name of the column Memo to something else, because may be it is conflicting with the keyword for creating Memo type column, once i have a column name DateTime and it was not functioning as well, when in changed the name to scheduledDateTime it worked.
Regards
Shajeel
|
|
|
|
|
|
Hello everyone!
I'm making an application interfaced with a DataBase (SQL).
If a table contains 1,000,000 records, i can't fill the table with all of them because it will take lot of time.
Is it possible to filter the record ten by ten (for example)?
I don't wanna load all the records and then display them ten by ten, but load everytime ten elements.
I hope you understand!
All suggestions are welcome...
Thanks in advance.
Enrico
VentoEngine corp.
Program your life ^^
|
|
|
|
|
Here is an idea you could try:
Read the records and store in DataTable "A"
Create another DataTable "B" and set your grid's datasource to this table.
Launch a thread to copy the records from DataTable A to DataTable B.
Use the System.Threading.Thread.Sleep to pause for a few milliseconds every 10 records. Using the Sleep method allows other processes to continue.
Hope that helps.
Regards,
Rudy.
|
|
|
|
|
it can be a good solution but i must do in the way i explained...
i just can't read all the records in the same time.
but great idea, i'll keep on mind ^^
VentoEngine corp.
Program your life ^^
|
|
|
|
|
You could just keep track of the last record that was displayed. Something like this:
int lastRecord = 0;
...
"SELECT * FROM someTable WHERE someColumn <= " + (lastRecord + 10) "AND someColumn >" + lastRecord
int lastRecord += 10;
If the user wanted to go back:
if (lastRecord != 10)
{
"SELECT * FROM someTable WHERE someColumn <= " + (lastRecord - 10) "AND someColumn >" + (lastRecord - 20)
int lastRecord -= 10;
}
Hope that helps
|
|
|
|
|
have i to build a stored procedure for that or...?
And what does "someColumn" is?
VentoEngine corp.
Program your life ^^
|
|
|
|
|
No that wouldnt be necessary just put that query in a DataAdapter and fill a table:
string selectText = "SELECT * FROM someTable WHERE someColumn <= " + (lastRecord + 10) "AND someColumn >" + lastRecord;
SqlDataAdapter dAdapt = new SqlDataAdapt(selectText, connectionHere);
DataTable table = new DataTable();
dAdapt.Fill(table, "tableName");
lastRecord += 10;
Just do this every time the user hits next or something.
|
|
|
|
|
how can i do if i don't have an ID column?
i can't compare the index...grrr
VentoEngine corp.
Program your life ^^
|
|
|
|
|
You don't have a primary key column that increments by 1?
SomeColumn(Primary Key)
1
2
3
4
etc.
There has to be some sort of pattern in the primary key column in order to do this.
|
|
|
|
|
I've added on my application a panel.
When the mouse come over i call the paint event for the panel and make e.graphic.DrawImage() drawing an image from global:Resource ...
But when i do so, it flickers, why?
|
|
|
|
|
You need to turn on double buffering. Look up SetStyle in the MSDN.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi
One & All
I m trying to do Message Center, which contains a DataGrid in that i need to get each boundcolumn a link button. So that i can redirect to next form to show the details of each message.
So pls Can anyone help me
Thanking u
Regards,
naren.
narendra.pk@gmail.com
|
|
|
|
|
|
Hello there
I want to get my project's form's name (maybe classe's name!),
How can i access them ?
Please notice that my project is MDI-Child, but i have child forms and none child forms, I can get child forms as below code, but no none child's.
<br />
foreach (Form childForm in MdiForm.MdiChildren) {<br />
MessageBox.Show (childForm.Name.toString());<br />
}<br />
Please help me
Thank you
|
|
|
|
|
If the Owner of all your shown Form s is set than have a look at the OwnedForms property.
|
|
|
|
|
Thank you dear Robert Rohde
It worked
I set my form's owner property programmatically to my MdiForm and i used below code to control forms that user open one instance of it.
<br />
private void btnOpenfrmMessage_Click(...)<br />
{<br /> //Controlling one instance of form :
<br />
foreach (Form owneForm in MdiForm.OwnedForms)
{<br />
if (owneForm.Name == "frmMessage")<br />
{<br />
owneForm.Focus();<br />
return;<br />
}<br />
}<br /> //Openning Form :
<br />
frmMessage copyfrmMessage = new frmMessage() ;<br />
copyfrmMessage.Owner = MdiForm ;
copyfrmMessage.Show() ;<br />
copyfrmMessage.Activate() ;<br />
}
-- modified at 1:57 Monday 8th May, 2006
|
|
|
|
|
OK, as usual I'm stuck in transition between my familiar C/C++ background and finding the C# equivalent.
This is really probably first grade stuff, but I've been beating my head for the last hour, reading through my books, help and basic texts and I need to just give up and ask for help getting back on track.
I'm importing a Win32 API function (because there is no .NET equivalent yet) that I need to call in my program. Basically this function requires a pointer. So I need to create a block of memory 2048 bytes long, manipulate it in a string fashion (set it to something) then give the Win32 API a pointer to the memory.
If this were C++ I could bang this out in 2 seconds and be done with it.
void MyFunction( char *astring)
{
char chunk[2048];
if(strlen(astring) > 2048)
return;
memset(chunk, 0, 2048);
strcpy( chunk, astring);
TheWin32APIFunc( (int *)chunk, 2048 );
}
But this is not C++, I'm in C# managed memory land. c# strings aren't zero terminated, I can't change the length of a string once it's created and c# and .NET really don't want me touching the actual memory directly so just doing a typecast isn't very appreciated by my compiler either.
Anyone feel like taking pity?
TheWin32APIFunc is formatted/prototyped thusly:
private static extern int TheWin32APIFunc( IntPtr data, Int32 datlen);
so I need a System.IntPtr and a plain Int32 (I got the Int32 covered).
Thanks in advance
-- modified at 1:15 Sunday 7th May, 2006
|
|
|
|