|
Hello!
I do my programm using Window Forms with C#. I create User Control element which draw some graphics inside and has some interaction with mouse. I place my control in Panel. But size of my Control is higher then Panel size, so, I set AutoScroll of Panel as true. But I find some problem - when I first time scroll down panel and click on my control, panel automaticaly scroll up. On second click (and etc.) panel scroll bar is not jumping to the top. How I can cancel this jump after first click? I need than panel stay on selected position after any click. Can anyone help me?
Additional: I found that it happening due to MyControl.Select() action... In this case scroll is jumping up to the top. How I can overcome this problem?
|
|
|
|
|
The problem has to do with focus. If you just click on your control, focus is given to the control with the first tab stop (TabStop set to 0). If you actually select a control in your UserControl , then it should scroll so that control is in view.
Also, a UserControl and all derivatives are scrollable themselves, so you don't need to put them in a Panel in order to auto-scroll. This might also help the problem of jumping to the top (which, like I said, is a focus thing and is by design) since the UserControl in control of scrolling now, not its parent Panel container.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
!urgent question!!
Now I have to call an Oracle Stored Procedure, which has a set of output parameters. Some parameters type are 'TABLE OF INTEGER'.
If I have to use OleDb, what kind of OleDbType I should use for the
corresponding parameter in Parameters of the OleDbCommand?
I tried IUnknown, LongVarBinary and PropVariant. They don't work.
Or is there any alternative?
Thanks in advance!
|
|
|
|
|
Output parameters of a table type are not supported by the System.Data.OleDb , though you could fanagle them somehow and parse the data yourself. I've seen an example of this a long time back, but it isn't a very efficient operation anyway.
Since you're using Oracle, why not use the Oracle.NET provider which is designed specifically for Oracle (just like SQL Server has had System.Data.SqlClient since .NET 1.0). The Oracle.NET provider is shipped with .NET 1.1 and is available for download somewhere on http://msdn.microsoft.com[^] for .NET 1.0 (they call it a beta, but that's only because they planned on releasing it for 1.1).
In System.Data.OracleClientOracleType I don't see any enum member for a table of data, but there is always RAW, which you can use a byte[] array with and parse out the INTs yourself.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I just installed OracleClient for .NET 1.0. Unlucky, I found those works in the help:
The PL/SQL TABLE data type is not supported by the Data Provider for Oracle. However, REF CURSORs are more efficient. If you must use a TABLE data type, use the OLE DB .Net Data Provider with MSDAORA.
It seems I should come back to use OLEDB. But was really stucked.
|
|
|
|
|
Unlucky indeeded! At least the help gave you a place to start by telling you what OLE DB provider to use.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
One more thing. Perhaps I didn't make things clear.
The problem is NOT if I can parse the data or not. I can't get the data at all.
I got this error message when I try to execute the stroed procedure:
"ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'GET_BREAKDOWN'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored"
Thanks for attention!
|
|
|
|
|
That information would've been helpful in the first post.
That documentation you mentioned in the sibling post above didn't specify what OleDbType to use, did it? If you could find an OLE DB tool (there was a good one that came with VB6, but I can't remember what it was called) that gave your the actual DBTYPE_* types of parameters it gets back, you could match those up using information in the OleDbType enumeration documentation. It's apparently possible since it was mentioned in those docs you could, so matching it up to an OleDbType seems to be the only hurdle, unless of course the functionality you need is buried in the C++ OLE DB interfaces and isn't encapsulated in .NET's OLE DB classes. Here's to hope!
I took a look at the OLE DB SDK and found something you probably won't like, though: there is a DBTYPE_ARRAY defined in OLE DB that you can combine with whatever array item type you want, but it isn't exposed in .NET's OLE DB classes.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Now I changed code to like:
OleDbParameter param = new OleDbParameter(sName, new int[5]);
Now I am getting System.FormatException instead of OleDbException from ORACLE.
This is the message text:
"Index (zero based) must be greater than or equal to zero and less than the size of the argument list."
Does it provide any clue?
|
|
|
|
|
That parameter won't get you anything. Don't declare it in your arguments otherwise you won't be getting it back out (you can't reference it).
In any case, the type has to be supported by the OleDbParameter . If there's not a corresponding OleDbType , it isn't supported.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi there
i made a webservice and then i added a web reference of it to my project
Now is it possible to change JUST the webservice's ADDRESS at runtime?
this.Url = "http://localhost/testing.asmx";
I want to change the address of my WS in
the reference.cs file at runtime
And if it is, then can someone plz tell me how?
some code might be nice!
VisionTec
|
|
|
|
|
You just did it yourself with that first line of code! Create an instance of your web service client proxy (which derives from WebClientProtocol ) and set the Url property to whatever you need it to be.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
And you can add a tag in your application setting file which indicate the url and at runtime read it.
Mazy
"Man is different from animals in that he speculates, a high risk activity." - Edward Hoagland
|
|
|
|
|
Hi everyone, I am fairly new to C# (2 months) and I need some serious help.
I need to populate a RadioButtonList (id=rbl) with the first set of data (QUESTIONID = 1) from a XML data (sports.xml).
I am having a hard time setting the DataTextField = "CHOICETEXT" and DataValueField = "CHOICEID".
I am not even sure if this is the best xml format either.
The code below the xml will cause an error. "System.Data.DataRowView' does not contain a property with the name CHOICETEXT"
Please help me to solve this problem. Thank you in advance.
<TEST>
<QUESTION>
<QUESTIONID> 1 </QUESTIONID>
<TYPE>radio</TYPE>
<TEXT>Who is the going to win the NCAA?</TEXT>
<CHOICES>
<CHOICE>
<CHOICEID> 1 </CHOICEID>
<CHOICETEXT>UAB</CHOICETEXT>
</CHOICE>
<CHOICE>
<CHOICEID> 2 </CHOICEID>
<CHOICETEXT>Kansas</CHOICETEXT>
</CHOICE>
</CHOICES>
<ANSWER> 1 </ANSWER>
<RESPONSE>
<CORRECT>You got that right baby!.</CORRECT>
<WRONG>ARE YOU CRAZY?</WRONG>
</RESPONSE>
</QUESTION>
<QUESTION>
<QUESTIONID> 2 </QUESTIONID>
<TYPE>radio</TYPE>
<TEXT>Who is going to win the Stanley Cup?</TEXT>
<CHOICES>
<CHOICE>
<CHOICEID> 1 </CHOICEID>
<CHOICETEXT>Red Wings</CHOICETEXT>
</CHOICE>
<CHOICE>
<CHOICEID> 3 </CHOICEID>
<CHOICETEXT>Maple Leafs</CHOICETEXT>
</CHOICE>
</CHOICES>
<ANSWER> 2 </ANSWER>
<RESPONSE>
<CORRECT>You got that right baby!.</CORRECT>
<WRONG>ARE YOU CRAZY?</WRONG>
</RESPONSE>
</QUESTION>
</TEST>
DataSet ds = new DataSet();
ds.ReadXml(MapPath("sports.xml"));
DataView dv = new DataView(ds.Tables["QUESTION"]);
dv.RowFilter = "QUESTIONID = 1";
rbl.DataSource = dv;
rbl.DataTextField = "CHOICETEXT";
rbl.DataValueField = "CHOICEID";
rbl.DataBind();
|
|
|
|
|
Because the DataRowView over that table wouldn't have those fields directly under its scope. In relation to the QUESTION scope, they would be CHOICES/CHOICE/CHOICETEXT and CHOICES/CHOICE/CHOICEID. Use these strings as your DataTextField and DataValueField except replace "/" with ".". This notation is supported in Windows Forms bindings, so it may just work here (things work a little differently).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello Heath,
Thank you for your reply. I tried your suggestion and got
"DataBinder.Eval: 'System.Data.DataRowView' does not contain a property with the name CHOICES.CHOICE.CHOICETEXT"
any other suggestions?
|
|
|
|
|
Not really. It's documented that it should work and IIRC I've done something similar before with success, except that I've never bound to a DataView and instead bound to a DataSet with DataGrid.DataMember set to the DataTable name I needed. I know this won't give you the filter you want, but you could try it to see if it works that way. Other than that, I'd recommend just reading about all the relevant properties like DataGrid.DataSource and DataGrid.DataMember , along with other related properties. There's a lot of information and examples buried in there.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hey all
For an example, lets say I want to pass 3 bstr's to an unmanged dll (using C#) and one is to be passed by reference because that will hold the output of the function call. So here's what I do (please ignore sytax):
Import the function:
[DllImport("mydll.dll")]<br />
void MyFunc( [MarshalAs(UnmanagedType.BStr)] string A, [MarshalAs(UnmanagedType.BStr)] string B, [MarshalAs(UnmanagedType.BStr)] ref string C);
Now, I use that function:
string output = "";<br />
MyFunc("test", "another", ref output);
Great, it works no prob, although, 'output' never changes. This is due to the fact that string isn't immutable, no biggy, I'll try the StringBuilder class in place of that string, so I have:
Import the function:
[DllImport("mydll.dll")]<br />
void MyFunc( [MarshalAs(UnmanagedType.BStr)] string A, [MarshalAs(UnmanagedType.BStr)] string B, [MarshalAs(UnmanagedType.BStr)] ref System.Text.StringBuilder C);
Now, I use that function:
System.Text.StringBuilder output = new System.Text.StringBuilder("");<br />
MyFunc("test", "another", ref output);
This failes with the following exception:
An unhandled exception of type 'System.Runtime.InteropServices.MarshalDirectiveException' occurred in winp2p.dll
Additional information: Can not marshal parameter #4: Invalid managed/unmanaged type combination (StringBuilders must be paired with LPStr, LPWStr, or LPTStr).
Now this makes sence since I'm trying to pass a BStr by reference, but I cannot find out how! Help please!!
Jason
|
|
|
|
|
Any particular reason why your using BStr's? BSTR's were native to VB6, not anything.NET...
Is your .DLL written to handle them?
RageInTheMachine9532
|
|
|
|
|
The dll i'm importing is the reason...
They are actually of type PWSTR, which, I read somewhere, is of type BSTR, so, when I use MarshalAs I can use UnmanagedType.BStr....
lets say the actual dll prototypes look like:
void myfunc(pcwstr a, pcwstr b, ppwstr c);
where ppwstr is just pwstr*
I need to be abel to pass 'c' in by reference so I can obtain my output.
|
|
|
|
|
schnee2k3 wrote:
They are actually of type PWSTR, which, I read somewhere, is of type BSTR,
Not quite. BSTR's begin with a 32-bit byte length preceding the array of Unicode characters. The length is in BYTES, not characters. You'd probably be better off Marshaling them as LPWSTR's. All PWSTR means is "Pointer to Wide (or Unicode) String". Kind of odd though, it's usually called LPWSTR (Long Pointer... Unless your actually using BSTR's in your app or .DLL, you'd be better off not using them.
Now, the reason why your string you passed by ref didn't change is because it had a zero length to start with. Managed strings are immutable, they can't change unless poked into directly. Unless your .DLL will deallocate and allocate you a new Managed string, you have to declare the string at a maximum size you can handle first. Something like either a character array of zero's to satisfy the termination character at the end of a string, or use Stringbuilder to do it. But even with StringBuilder, you have to tell it to allocate enough space to handle the maximum size string you expect to get back.
RageInTheMachine9532
|
|
|
|
|
So, here is what I did:
Importing the function:
<br />
[DllImport("mydll.dll")]<br />
public static extern void MyFunc([MarshalAs(UnmanagedType.BStr)] string A, <br />
[MarshalAs(UnmanagedType.BStr)] string B, <br />
[MarshalAs(UnmanagedType.LPWStr)] ref System.Text.StringBuilder C);<br />
The actual call:
<br />
System.Text.StringBuilder dataOut= new System.Text.StringBuilder(1024);<br />
<br />
MyFunc(someString, anotherString, ref dataOut);<br />
This doesn't work because the pwstr is not the same as an lpwstr. I can verify that the dll is using A and B correctly as BStr's. I get an unhandled exception:
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in winp2p.dll
Additional information: Capacity exceeds maximum capacity.
I know for a fact also, that 1024 is WAY more than enough to hold what I need. I think this is happening because, I believe, that a PWSTR is not necasariy null terminated??
Anyways, the following code DOES work, although I HATE that it's in an unsafe block:
Importing the function:
<br />
[DllImport("mydll.dll")]<br />
public static extern void MyFunc([MarshalAs(UnmanagedType.BStr)] string A, <br />
[MarshalAs(UnmanagedType.BStr)] string B, <br />
ref IntPtr C);<br />
The actual call:
<br />
IntPtr dataOut = Marshal.AllocCoTaskMem(1024);<br />
string foo;<br />
<br />
unsafe<br />
{<br />
MyFunc(someString, anotherString, ref dataOut);<br />
foo = new string((char*)dataOut.ToPointer());<br />
}<br />
<br />
Marshal.FreeCoTaskMem(dataOut);<br />
In the above example, I do, in fact, get the string I am looking to get, BUT I really really really hate the unsafe block....
|
|
|
|
|
Dave's right - just use UnmanagedType.LPWStr - except the reason it's not working is because you're <cod>ref'ing your string. A string is already a reference type, so what you're doing is actually more like LPWSTR* , or a pointer to a pointer to a wchar_t . Don't use ref or out with reference types unless you need double-pointers (it happens).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath-
Here's the new code with your suggestions:
Importing the function:
[DllImport("mydll.dll")]<br />
public static extern void MyFunc([MarshalAs(UnmanagedType.BStr)] string A, <br />
[MarshalAs(UnmanagedType.BStr)] string B, <br />
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder C);
The actual call:
System.Text.StringBuilder dataOut= new System.Text.StringBuilder(1024);<br />
<br />
MyFunc(someString, anotherString, dataOut);<br />
<br />
string dataOutAsString = dataOut.ToString()
dataOutAsString contains 2 unkown characters (the boxes in debug). This is not anything close to what it should be returning. Removing [MarshalAs(UnmanagedType.LPWStr)] from the import does nothing, still just the 2 unkown characters.
Jason
|
|
|
|
|
Without seeing the garbage in a debugger, it would appear that the function you called filled in ASCII characters (8-bit), instead of the 16-bit Unicode characters that StringBuilder is looking for.
One clue would be how long is the string compared to the length you expect. Is it just about half as long?
Another would be to look at the values in the chars[] array in the StringBuilder. Parse out the values for high and low bytes and check them against the ASCII table to see if your actually getting two 8-bit characters crammed into a single 16-bit character field.
RageInTheMachine9532
|
|
|
|
|