|
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# !
|
|
|
|
|
Hi All,
I have a class called Database.cs which is called when my application is started up. This class then populates 2 arrays with data from my SQL database.
--Update--
I have also just noticed that once I move to another part of my application these arrays seem to vanish? am I going about this all the wrong way?
--Update--
Now I am trying to access these arrays and am running into problems.
I have the following code so far.
===============
Database sn = Database();
int j = sn.StaffNames.getUpperBound;
===============
Which doesn't work and if I change the first line to Database sn = new Database(); I think it is clearing my arrays?
Thanks,
|
|
|
|
|
Gavin_Mannion wrote:
int j = sn.StaffNames.getUpperBound;
Assuming StaffNames is the array; the name should be GetUpperBound (uppercase G), and it is a function that takes an integer specifying which dimension you want the upper bound from.
int j = sn.StaffNames.GetUpperBound(0);
That should give you the value you wanted, and yes the first line should be Database sn = new Database() assuming you are meaning to create a new instance of your Database class.
The only thing that could cause your arrays to be cleared is by either calling Clear() on the array, or by assigning a new array to it.
I have a feeling that it only seems that your arrays are being cleared though, so try the first fix and if that doesn't work reply back and I'll look into it further. More code would help as well, at least a generalized version of your code
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
|
|
|
|
|
Okay the error message I get is the following
------------------
An unhandled exception of type 'System.NullReferenceException' occurred in LTBRMaintenance.exe
Additional information: Value null was found where an instance of an object was required
------------------
My code looks like this
===============
Database sn = new Database(); //Database is the name of my class
int h = sn.StaffNames.GetUpperBound(0); //StaffNames Array Name
===============
My Database.cs code looks like this
===============
public class Database
{
public string[] StaffNames;
public Database()
{
}
public void LoadStaff()
{
SqlConnection myConnection;
myConnection = new SqlConnection("server=127.0.0.1; uid=;pwd=;database=LondonTBR");
string sql = "ltbr_GetStaff 0";
// Connect to the SQL database using a "Stored Procedure"
SqlCommand myCommand;
myCommand = new SqlCommand(sql, myConnection);
myConnection.Open();
SqlDataReader dReader;
dReader = myCommand.ExecuteReader();
int j = 0;
int ArrayCount = 0;
//Set Array to correct size
if (dReader.Read())
{
ArrayCount = dReader.GetInt32(0);
StaffNames = new string[ArrayCount];
}
dReader.NextResult();
//Populate Array
while (dReader.Read())
{
StaffNames[j] = dReader.GetString(2) + ", " + dReader.GetString(1);
j = j + 1;
}
dReader.Close();
myConnection.Close();
myCommand.Dispose();
}
}
}
===============
If I step through the code the function LoadStaff() is called and does execute without any problems.
Let me know if you spot something I am doing wrong here
Thanks,
|
|
|
|
|
When is the LoadStaff() function called?
In the first code block you create the Database object then immediately try to read the StaffNames without calling the Load.
If you will always be calling LoadStaff when you create a Database object you should place a call to LoadStaff() in the constructor for the Database class.
If you won't be calling LoadStaff everytime then you should create a new StaffNames array.
public Database() {
LoadStaff();
} or
public Database() {
StaffNames = new string[0]
} 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
|
|
|
|