|
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.
|
|
|
|
|
I think the fixed keyword is used to lock memory for passing arond like this. I also believe you need to use the System.Text namespace to find a function that returns a byte [], which will be your string converted to one byte per char. A C# string type is Unicode, and therefore is two bytes per character.
And, once it's a byte [], you can manipulate it any way you like.
www.pinvoke.net is the place to go to see examples of pinvoking API calls, yours may be in there.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks Christian,
I appreciate your attempt here, but I'm afraid I'm too lost.
As I said to digitalKing above. I've literally spent the last 5 hours mired trying to pick apart the various methods to do this.
I have no doubt, there's probably at least a dozen ways and I'll bet I've tried 30.
I've been reading every book on my library on C# strings, pointers, how they work, what they don't do. Other classes, like StringBuilder, Marhsal, pinning, pinvoke
My brain is mush and all these terms are now just jumbled into one big mess.
What I need at this point is a simple example showing the csharp equivalent of the code I provided.
FTR, the actual API function I'm using is AVIFileWriteData() and I've also googled it and searched out every possible example, but that function is so rarely used (it writes ancillary information data into a AVI header) by anyone that nobody bothers to include it in their port of the AVI functions into .NET.
Trust me, there is no example of this particular functions use in managed code, but I really didn't think it made any difference, all I'm trying to do is make a string then pad it up to 2048 characters (I won't go into why it needs to be 2048, it just does) and then give this function a pointer to the data. Why does this have to be so hard?
regards,
Phil
|
|
|
|
|
It looks to me like if you create a byte array of 2048 bytes, and then manipulate it, you'll be able to do something like
unsafe
{
byte * bytes = myArray;
// pass the pointer in to your function
}
AVIFileWriteData appears to take an LPVOID, so it doesn't really matter what you pass it, so long as it's a pointer to the array in memory
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Yup, you're right, it really doesn't matter what I pass it so long as it's a pointer to the string memory.
But if I do it like you said then I have this myArray buffer that becomes difficult to print simple strings to.
ie. then I'm left with the question:
how to I format text into myArray?
My approach was to have MyFunction() encapsulate all this ugliness and just make a simple c# call inside my main program like:
string aviinfo = "[Timing] Frame Rate=250 Mark Frame=9";
PhilsFunction( aviinfo);
Inside Philsfunction is the ugliness of converting this simple ordinary c# string into a padded 2048 byte area of memory and delivering the pointer to AVIWriteFileData()
it's the conversion, padding and pointer part that has me stuck.
|
|
|
|
|
string s = "test this, sucka";<br />
ASCIIEncoding enc = new ASCIIEncoding();<br />
byte[] b = enc.GetBytes(s);<br />
<br />
unsafe<br />
{<br />
byte [] b2 = new byte[2048];<br />
Array.Copy(b, 0, b2, 0, b.Length);<br />
<br />
fixed (byte * send = b2)<br />
{<br />
<br />
}<br />
}
As far as I can tell, this starts with a string ( build it however you like ) and then turns it into a byte [], then it creates a second byte [], of fixed size, copies the contents of the first into the new array, then turns that into a fixed size pointer.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
OK, now that solution I definitely never would have come up with!
It does compile anyway. I had to modify my prototype to to to a byte * instead of an System.Intptr the way I originally had it (not a big deal, although it would have been nice to keep all the pointer types consistent throughout this class...all the rest of the API Functions were done that way).
Running the debugger does seem to show it working. The API function is throwing a nasty exception though, I'm not convinced it likes this byte pointer and I'm not sure how to browse memory to confirm this pointer is really pointing to my actual buffer of data.
I'm assuming you wanted me to call:
AviFileWriteData( ..., send, 2048);
In other words "send" is the pointer?
(obviously I've never used the fixed keyword before so this whole syntax is another new adventure).
I should be able to figure it out from here anyway.
At least I got the thing to compile. For me, that's 90% of it, I can usually tweak, adjust and debug from there.
thanks Christian
(P.S. this all still strikes me as a HUGE pain in the butt compared to the old C++ way, I'll never be convinced C# is better).
|
|
|
|
|
Phil C wrote: (P.S. this all still strikes me as a HUGE pain in the butt compared to the old C++ way, I'll never be convinced C# is better).
C# is plainly not 'better' It's 'better at certain tasks'. For example, if time is an issue, I'd prefer to work in C# than C++. If speed is an issue, it's gotta be C++. But really, it's potential to get messy definately increases when you need to do this sort of stuff to bridge the two.
I'm very happy to know C#, but I'll never abandon C++, even if I find myself using it a lot less nowadays.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
My exception fault was from a mistake on one of the other params - unrelated and I thought so when I first saw it.
This did work Christian. It's a bit ugly, but at least all the ugly stuff is isolated inside my AVI class.
I'd still be spinning my wheels if you hadn't stepped in. Thanks again. Now I can sleep
Phil
|
|
|
|
|
No worries, glad to help. To be honest, I only vaguely knew where to look for the answer ( hence my initial, vague comments ), so I was glad to look them up and learn it for sure, for myself.
I've actually never used the 'fixed' keyword myself, I've just read about it...
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Phil,
You can also try using the Marshal static functions.
For example:
<br />
string s = new string(" ", 2048);<br />
IntPtr ptr = Marshal.StringToHGlobalAnsi(s);
Then you can pass ptr to your method.
There are other helpful functions available in Marshal that you may be able to use such as: Marshal.AllocHGlobal, or Marshal.PtrToStringAnsi .
Regards,
Rudy.
|
|
|
|
|
Im having problems updating my grid. The grid loads fine, the edit button functions fine(bringing up textboxes)...I update the data....click "Update" and it reloads the grid. I think this is caused because my form load reloads the grid again but I can't seem to get my grid to show unless I do this.
Attached is my form load and update statement....(ps. it enters my update function but the text value is the pre-updated value)
<br />
public void Page_Load(Object sender, EventArgs e)<br />
{ <br />
_sqlStmt = "SELECT Nm as [Name], OfficeNm as [Office Name], HomePhone as Home, OfficePhone as Office, Address FROM contacts";<br />
oleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\\db.mdb";<br />
oleDbDataAdapter1.SelectCommand.CommandText = _sqlStmt;<br />
dataSet1.Clear();<br />
oleDbDataAdapter1.Fill(dataSet1, "Contacts");<br />
BindGrid();<br />
}<br />
<br />
<br />
void BindGrid()<br />
{<br />
Trace.Write ("**IN_BindGrid");<br />
MyDataGrid.DataSource = dataSet1.Tables["Contacts"].DefaultView;<br />
MyDataGrid.DataBind();<br />
}<br />
<br />
<br />
public void MyDataGrid_Update(Object sender, DataGridCommandEventArgs e) <br />
{<br />
Trace.Write ("**In_MyDataGrid_Update");<br />
string Name = ((TextBox)e.Item.Cells[1].Controls[0]).Text;<br />
string OfficeNm = ((TextBox)e.Item.Cells[2].Controls[0]).Text;<br />
string Home = ((TextBox)e.Item.Cells[3].Controls[0]).Text;<br />
string Office = ((TextBox)e.Item.Cells[4].Controls[0]).Text;<br />
string Address = ((TextBox)e.Item.Cells[5].Controls[0]).Text;<br />
<br />
oleDbDataAdapter1.Update(dataSet1);<br />
BindGrid();<br />
}<br />
<br />
Any help is greatly appreciated....
-Kay
-- modified at 23:13 Saturday 6th May, 2006
|
|
|
|
|
Hi..
I want to use the CmdLoadFromResource() method of ths speech SDK 5.1 to make the xml file that includes the Grammar embeded but i dont know how to use this method in C#.
Does any one know how to use this method?
|
|
|
|
|
|