|
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
|
|
|
|
|
Which API function are you using?
You can probably use the StringBuilder class (from System.Text), and (depending on the function) replace the IntPtr argument with one of type StringBuilder.
|
|
|
|
|
I knew that question was coming, I tried to just focus on the problem and keep it simple.
If it makes any difference (and I don't honestly know why it does)
the full function is:
AVIFileWriteData( IntPtr aviStream, Int32 ckid, IntPtr lpBuffer, Int32 cbBuffer);
It's part of the SDK AVI functions located in AVIfile32.dll. The C++ header files and library are vfw.h and vfw32.lib if I were working in C++ (but I'm not)
Basically I have already got all the other parameters of this function figured out because there are plenty of examples on how to port AVI functions to Csharp to work with. Sadly, no examples include this function and I need to use it so I'm tyring to bring it into the project.
So, to restate the question, I need to deliver to this function a "pointer" (lpBuffer) to an area of memory that I need to be exactly 2048 bytes long. I'm going to be formatting that data something like:
[Timing] Frame Rate=250 Mark Frame=9 Time at Mark Frame=0 ....
and whatever of the 2048 sized buffer that's left over needs to be padded with zeroes.
I did also look at the StringBuilder class. I read Petzold's whole chapter on strings and I've also been reading MSDN info on it for at least 5 hours now. I also checked through two other O reilly books I have in my library.
Really, I'm not being a idiot, I've honestly tried to figure this out on my own before running for help. But I'm completely lost in the syntax of what I need to do. I have so many posibilities and options running through my head at this point I can't tell which combination of the 15 different ways will work.
Just telling me to use the StringBuilder class really doesn't help at this point. I need a pointer, not the name of a class.
|
|
|
|