|
Profox Jase wrote:
public static extern long PlaySound(String lpszName, long hModule, long dwFlags);
Your problem is the long type. In C# this is a 64 bit int. You should use int instead.
--
Peter Stephens
|
|
|
|
|
Cool, thanks again.
J
Jason King
jason.king@profox.co.uk
Feel the love at www.profox.co.uk
|
|
|
|
|
Hi All,
I have a form which has a dropdown list on it which is being populated by an array. What I am trying to find out how to do is set a value for a option in the dropdown list so that I can query the database using a Integer and not a text field.
Example:
My Drop Down list has the following
Option 1: London
Option 2: Liverpool
Option 3: Other
If my user selects 'Liverpool' I would like to get the value '42' which is the unique ID in the database that is connected to Liverpool.
In ASP and VB you where just able to add a value to the field, can this be done in C#?
Thanks,
|
|
|
|
|
If your working in ASP.net, one of the the Add overrides lets you specify a ListItem class, which takes two strings. These map to the text of the option and the value of the option in html. Value can be retrieved from SelectedItem.Value, and the text from SelectedItem.Text.
I expect C# for apps is fairly close, but there are definately differences between the two. One difference I expect is the ability to map an object to the string instead of a second string.
// Rock
|
|
|
|
|
Using ASP I have been able to do it and that is why I expect it to be at least similar in a C# Application. There just doesn't seem to be a possible option for value which is mind boggling if they have decided to scrap that one.
Please let me know if you come across anything that explains this, also how do you mean
CLaW wrote:
One difference I expect is the ability to map an object to the string instead of a second string. ????
Thanks
|
|
|
|
|
Hi Gavin
The ComboBox in .NET receives a generic object. This is pretty powerful, but also is quite a change to the normal VB-style. All that's required is to create a simple (or more complex) class and use that to add to the ComboBox.
To get values out, just cast to your object and call your custom props. The ToString() override caught me out, but the ComboBOx uses it to show values.
private void Form1_Load(object sender, System.EventArgs e)
{
comboBox1.Items.Clear();
comboBox1.Items.Add(new cComboLoader("Bill",1));
comboBox1.Items.Add(new cComboLoader("Steve",2));
comboBox1.Items.Add(new cComboLoader("Paul",3));
comboBox1.Items.Add(new cComboLoader("Reinout",4));
}
private void button1_Click(object sender, System.EventArgs e)
{
MessageBox.Show(((cComboLoader)comboBox1.SelectedItem).ToString());
MessageBox.Show(((cComboLoader)comboBox1.SelectedItem).myIndexVal().ToString());
}
public class cComboLoader
{
private string _Txt="";
private int _iVal=0;
public cComboLoader(string sTxt, int iVal)
{
_Txt=sTxt;
_iVal=iVal;
}
public override string ToString()
{
return _Txt;
}
public int myIndexVal()
{
return _iVal;
}
}
Does this help you?
Cheers,
Simon
X-5 452 rules.
|
|
|
|
|
Wow, just a little bit more complicated than VB ...
Well that is exactly what I was looking for but as usual it has arrived about 2 hours after I came up with another solution. I will keep it in my code bank though because it is most probably better than mine ..
What I have done is load a 2 dimensional array with the ID's and strings, then loaded the combobox with the string. When a option is chosen it loops through my Array to find the matching ID.
Hey it works
Thanks for the help though
|
|
|
|
|
You can easily combine the 2 solutions by using the temp. inline cComboLoader class in your Combo.Items.Add.
What will happen if you get 2 values with the same text, but diff. ID's?
Cheers,
Simon
X-5 452 rules.
|
|
|
|
|
There is another way, it involves using the DataSource, DisplayMember and ValueMember properties of the combo box. If I weren't late for work I'd describe exactly how to use it, but if you search the docs for DisplayMember there is an example of using it
James
Sonork ID: 100.11138 - Hasaki
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
Hi,
I have a Socket which is binded to a local UDP endpoint. When recieving data using the Recieve() funtion, the host may timeout and my program just sits there.
Any idea on how to set a timeout ? I remember java having a method to do it which throws an exception if the timeout occours.
Any ideas people ?
Cheers
|
|
|
|
|
Hi
I am using a DLL, where one of the functions need a pointer to a C/C++ struct, here is the struct :
struct Transaction {
char card_number[21];
int card_expirymonth;
int card_expiryyear;
}
So I need to be able to declare the struct in C#, and pass a pointer from the C# "struct/class" to the DLL funcion. Of cause the sizeof should be the same. I hope it can be done
Thanks
Felix
|
|
|
|
|
When you have a struct of simple datatypes creating the struct should be fairly easy.
[StructLayout(LayoutKind.Seqential)]
public struct Transaction {
[MarshalAs(UnmanagedType.LPStr, SizeConst=21)] string card_number;
[MarshalAs(UnmanagedType.U4)] int card_expirymonth;
[MarshalAs(UnmanagedType.U4)] int card_expiryyear;
} Of course this is untested code, but I believe that is correct attributes used.
HTH,
James
Sonork ID: 100.11138 - Hasaki
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
Hi James,
THX - I'll try that , btw. is it possible to use the sizeof() function on the struct?
Felix
|
|
|
|
|
I have the same problem
i have to pass a pointer to the DOC_INFO_1 structure via the winapi
StartDocPrinter(handle, data, *DOC_INFO_1)
DOC_INFO_1
{
LPTSTR pdocname
LPTSTR pdatatype
LPTSTR poutputfile
}
can anyone help me?
|
|
|
|
|
Oops, I think there is an error in what I suggested trying.
[StructLayout(LayoutKind.Seqential, CharSet=CharSet.Ansi)]
public struct Transaction {
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=21)] public string card_number;
[MarshalAs(UnmanagedType.U4)] public int card_expirymonth;
[MarshalAs(UnmanagedType.U4)] public int card_expiryyear;
} What I told you the first time would have been correct if card_number were a pointer to a char* and not an array in the struct.
Sorry about that,
James
Sonork ID: 100.11138 - Hasaki
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
Hi James,
Thanks, I did some testing Yesterday, and it did'nt work, when I passed the struct to the DLL, it got a the pointer to "card_number", and the DLL was unable to fetch the other fields.
Felix
|
|
|
|
|
Hi James,
It seems to working as a CHARM
Thanks again
Felix
|
|
|
|
|
No problem, I learned a bit myself
James
Sonork ID: 100.11138 - Hasaki
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
If have to use the api
StartDocPrinter(handle,level,DOCINFO) in C#
but getlast error = can't find module
maybe there is a problem with the predefined structure DOCINFO.
Is there anyone that has already used this kind of function.
thanks
Filip.
|
|
|
|
|
when is use this code in VB6.0 it works
but when i try to import the functions via C# (dllimport) it doesn't work
//VB6.0 code
Option Explicit
Private Type DOCINFO
pDocName As String
pOutputFile As String
pDatatype As String
End Type
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function OpenPrinter Lib "winspool.drv" Alias _
"OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, _
ByVal pDefault As Long) As Long
Private Declare Function StartDocPrinter Lib "winspool.drv" Alias _
"StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
pDocInfo As DOCINFO) As Long
Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function WritePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, _
pcWritten As Long) As Long
Private Sub Command1_Click()
Dim lhPrinter As Long
Dim lReturn As Long
Dim lpcWritten As Long
Dim lDoc As Long
Dim sWrittenData As String
Dim MyDocInfo As DOCINFO
lReturn = OpenPrinter(Printer.DeviceName, hPrinter, 0)
If lReturn = 0 Then
MsgBox "The Printer Name you typed wasn't recognized."
Exit Sub
End If
MyDocInfo.pDocName = "AAAAAA"
MyDocInfo.pOutputFile = vbNullString
MyDocInfo.pDatatype = vbNullString
lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)
Call StartPagePrinter(lhPrinter)
sWrittenData = "How's that for Magic !!!!" & vbFormFeed
lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, _
Len(sWrittenData), lpcWritten)
lReturn = EndPagePrinter(lhPrinter)
lReturn = EndDocPrinter(lhPrinter)
lReturn = ClosePrinter(lhPrinter)
End Sub
|
|
|
|
|
I'm looking for a tool that will instrument & then profile my C# components.
Does anyone know where I can find one?
I downloaded the "DevPartner Profiler" from Compuware, but it doesn't allow me to start the profiling.
Cheers,
Simon
X-5 452 rules.
|
|
|
|
|
Sorry, I got this to work.
Check it out here
Cheers,
Simon
X-5 452 rules.
|
|
|
|
|
How can I retrieved the File Icon and File Type like Windows Explorer
Thanks
BLaZiNiX
|
|
|
|
|
|
you don't know a method to make it like VC++
- Initialize the ImageList with SHGetFileInfo
- Make a GetShellIcon function return SHFILEINFO.iIcon
- Make a function to find the type of the file
I'm not sure but i think i can make it with a VC++ DLL and import it in C# !
|
|
|
|