|
Hi,
ComboBox (and ListBox) collect items of any type you choose, not just string.
So you can create a special item class to hold whatever you want, and add
instances of that class to your ComboBox.
Now you should use ComboBox.DrawMode=OwnerDrawFixed and do the item painting
yourself using the ComboBox.DrawItem event.
|
|
|
|
|
Thanks i will try
is it too much to as a for a code sample...;)
Have a nice Day
|
|
|
|
|
Good news, you dont need OwnerDraw, it suffices to provide a ToString() method.
Example:
class cbi {
public int i;
public string text;
public cbi(int i, string text) { this.i=i; this.text=text; }
public override string ToString() { return text+" "+i; }
}
public Form1() {
InitializeComponent();
cb.Items.Add(new cbi(1, "a"));
cb.Items.Add(new cbi(2, "b"));
cb.Items.Add(new cbi(3, "c"));
cb.SelectedIndexChanged+=new EventHandler(cb_SelectedIndexChanged);
}
void log(string s) {Console.WriteLine(s);}
void cb_SelectedIndexChanged(object sender, EventArgs e) {
cbi item=(cbi)cb.SelectedItem;
if(item==null) log("item=null");
else log("item i="+item.i);
}
|
|
|
|
|
Doesn't a combo box have a display item and data item property ? Or is that just a combo box in a web page ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I cant find such property
only Item.
Have a nice Day
|
|
|
|
|
Hi, this is an example of the technique Christian refered to:
class cbi {
private int val; public int MyVal { get { return val; } }
private string name; public string MyName { get { return name; } }
public cbi(int i, string text) { this.val=i; this.name=text; }
}
public Form123() {
InitializeComponent();
ArrayList list=new ArrayList();
list.Add(new cbi(1, "a"));
list.Add(new cbi(2, "b"));
list.Add(new cbi(3, "c"));
cb.DataSource=list;
cb.DisplayMember="MyName";
cb.ValueMember="MyVal";
cb.SelectedIndexChanged+=new EventHandler(cb_SelectedIndexChanged);
}
void log(string s) {Console.WriteLine(s);}
void cb_SelectedIndexChanged(object sender, EventArgs e) {
cbi item=(cbi)cb.SelectedItem;
if(item==null) log("null");
else {
int i=(int)cb.SelectedValue;
log("i="+i);
}
}
It uses an ArrayList (or any other collection) as the source of all ComboBox data;
each item must now have two properties, one giving the text to display, one
giving the value to be returned by ComboBox.SelectedValue
|
|
|
|
|
Thanks a lot
i am now working with the code
Have a nice Day
|
|
|
|
|
|
Hi!
I am trying to get all the file names from a selected folder.
How can i get them useing the FolderBrowserDialog.
Thanks
|
|
|
|
|
Hi!
You can't.
FolderBrowserDialog is not the correct class for this.
You can get all the files in a given directory with the Directory class (System.IO namespace).
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
In the Database query I can write somthing like this:
SELECT fields FROM table <br />
WHERE somField LIKE '*someThing*'
When I tried to pass the above as the SelectCommand of the Adapter
It gives no result for the same 'someThing' which already returned results inside the database.
Can anybody explain the reason and advise a solution
Mohamed Gouda
Egypt
|
|
|
|
|
In SQL the wildcard characters are different from what you are used to.
% must be used instead of * in the query:
SELECT fields FROM table WHERE someField LIKE '%someThing%'
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Many Thanks
Mohamed Gouda
Egypt
|
|
|
|
|
Mohammed Gouda wrote: I imagined that there is Adapter.Clear(DataSet) or anything similar
To clear a DataSet, you don't need an adapter. DataSet.Clear()[^] does the job.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
|
Don't feel bad about asking 'silly' questions or being a newbie; everybody was at some stage.
A word of advice, though - don't delete questions after they've been answered.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
Hi,
I got a very simple XML file:
<rss version="2.0">
<channel>
<book>Book title
And want to have it printed in my c# application.
It should open the xml file from my website (http://my-website.com/books.rss), and then echo what's inside <book>.
Can anyone make simple and lightweight code do do that?
|
|
|
|
|
I can't connect app to SQLEXPRESS via the local network.
It works on same PC.
In SQL Server Configuration Manager > SQL Server 2005 Network Configuration > Protocols for SQLEXPRESS > TCP/IP and Named Pipes - set to Enabled.
In Server Properties > Security > SQL Server and Windows Authentication mode is set.
Firewall and antivirus are stopped during tests.
What else can be cause of this trouble?
Thanks for any help.
|
|
|
|
|
What is the error message?
What does your connection string look like?
What are the instance names of the two SQLEXPRESS servers?
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Thank you for your answer. More precisely:
Error message:
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Connection string:
mConnection = new SqlConnection(@"data source= computerNameServer\sqlexpress;" +
"database=myDatabase;" +
"UID=x; PWD=y;");
|
|
|
|
|
And the instance name on the other computer really is 'sqlexpress'?
I'm quite sure the instance name is case insensitive, but you could give it a try. By default, the instance name is SQLEXPRESS, IIRC.
Did you restart the computer after modifying the remote access settings for SQLServer?
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
It's quite easy to get the current type from an instance method e.g. this.GetType() but is it possible to get the name of the current type from within a static method?
For example:
class MyClass
{
static void MyMethod()
{
// how to get the current type from here
}
}
Wal
http://www.waleedeissa.com
|
|
|
|
|
Interesting question.
Can be solved using StackFrame :
class MyClass
{
static void MyMethod()
{
StackFrame sf = new StackFrame();
MethodBase mb = sf.GetMethod();
Debug.WriteLine("Currently in "+mb.DeclaringType.ToString()+"."+mb.Name+"()");
}
}
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
> Interesting question.
and a more interesting answer, thanks a lot
Wal
http://www.waleedeissa.com
|
|
|
|
|
Never rely on StackFrame, you might get different results when the JIT decides to inline the call to your method.
|
|
|
|