|
You need to cast the value.
E.g. int theInt = (int) ComboBox.selectedValue;
|
|
|
|
|
Thanks to reply me but i did this casting but it give me this message
specified cast is not Valide
Thanks for your time please help me
|
|
|
|
|
I'm not quite sure what you are trying to do but you can always use the debugger watch windows to determine the type of the object.
|
|
|
|
|
How are you loading the combo?
|
|
|
|
|
this my code:
private void cob_SelectedValueChanged(object sender, System.EventArgs e)
{
label1.Text = cbo.SelectedValue.ToString();
SqlConnection cnn = new SqlConnection();
cnn.ConnectionString = "workstation id=UNKNOW;packet size=4096;user id=sa;data source=UNKNOW;persist security info=False;initial catalog=TestDB;";
SqlCommand cmd = cnn.CreateCommand();
cmd.CommandType = CommandType.Text;
//int x = (int)cbo.SelectedValue;
cmd.CommandText = "Select * from Val Where Cat_ID = "+cbo.SelectedValue+"";
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
lst.DataSource = ds.Tables[0];
lst.DisplayMember = "Val_Name";
lst.ValueMember = "Cat_ID";
}
Thanks for your time ....
haytham
|
|
|
|
|
I assume that this is working ok? Or is it Returning the object name? If not, how are you filling the combobox, databind or by item? SelectedValue is only used with databinding, a ValueMemeber must be set.
webhay wrote:
label1.Text = cbo.SelectedValue.ToString();
The following will not work because it will return the object name.
webhay wrote:
cmd.CommandText = "Select * from Val Where Cat_ID = "+cbo.SelectedValue+"";
|
|
|
|
|
i filled the combobox with databind :
SqlConnection cnn = new SqlConnection();
cnn.ConnectionString = this.ConnStr;
SqlCommand cmd = cnn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = this.SelectCommand;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
combobox.DataSource = ds.Tables[0];
combobox.DisplayMember = ds.Tables[0].Columns["Client_Name"].ToString();
combobox.ValueMember = ds.Tables[0].Columns["Client_ID"].ToString();
|
|
|
|
|
webhay wrote:
combobox.DataSource = ds.Tables[0];
combobox.DisplayMember = ds.Tables[0].Columns["Client_Name"].ToString();
combobox.ValueMember = ds.Tables[0].Columns["Client_ID"].ToString();
You are not properly binding your combobox. Try this:
combobox.DataSource = ds;
combobox.DisplayMember = "TableName.Client_Name";
combobox.ValueMember = "TableName.Client_ID";
Note it is not recomended to use `ds.TableName' for the datasource.
|
|
|
|
|
Thanks Brett
it is working now you are so helpful
thanks for your time
and it is working in early binding too...
Regards
webhay
|
|
|
|
|
Thanks Brett
it is working fine now.you are so helpful....
Thanks for your time....
it is working in Erely binding tooo...
;)
regards
webhay
|
|
|
|
|
I am writing an RSS reader in C# and I'm trying to write the contents of a TreeView to an XML file. I have tried using XmlWriter and have managed to write simple tree structures but I get confused when it comes to dealing with complex tree structures such as those that have multiple folders and sub folders.
I have tried searching Code Project and the Net but haven't had much joy in finding a solution. I have only been using C# for a few months and my programming knowledge is fairly limited.
Is XmlWriter the best way to write out a TreeView? How would you go about going through each of the folders and writing the feeds within them?
If there is anything else that I need to include let me know.
|
|
|
|
|
Not a very popular article but you can try: http://www.thecodeproject.com/csharp/treeviewtoxml.asp
XmlWriter should be very easy. If you run into any problems try using the XmlDocument instead.
|
|
|
|
|
hi..
let say i have 3 nodes in a TreeView
and i wanna swap the 2nd and the 3rd node..
here is my code segment.. but it doesn't work
TreeNode tempNode = treeView1.Nodes[1];
treeView1.Nodes[1] = treeView1.Nodes[2];
treeView1.Nodes[2] = tempNode;
the tree becomes a 5-node tree like this:
Node0
Node2
Node1
Node1
Node2
|
|
|
|
|
you must remove and re-add the nodes as the setter in TreeView.Nodes[int] actually does an Insert.
<br />
TreeNode node1 = treeView1.Nodes[1];<br />
TreeNode node2 = treeView1.Nodes[2];<br />
treeView1.Nodes.Remove(node1);<br />
treeView1.Nodes.Remove(node2);<br />
treeView1.Nodes.Add(node2);<br />
treeView1.Nodes.Add(node1);<br />
|
|
|
|
|
It seems we have to install the whole .net framwork before run c# application on WinXP.But even if I install the .net framwork 1.1 package on Win2000,my C# application still cannt run on it.Since C# is better than VC++,why the application developed with it has such a unbearable restriction?
If we have to asked our users to install the .net framwork before run our application? or if there someother way to let our C# application run fluently on WinXP,Win2000,WinMe,Win98?
Thanks
momer
|
|
|
|
|
Well, same situation here, different results:
Developing apps for the company under WinXP with VS.NET 2003 Enterprise Architect, Clients running Win2000 Prof with installed .NET-FW. No problems at all.
The FRAMEWORK should be available for Windows 98SE and higher, btw. Do not try and install the SDK on Win98.
But even that should work under W2K.
Maybe you have deployed your app for the 1.0 Framework and installed the 1.1 Framework on your client?
Installing the FW as admin should work. There may be a problem with your config, I have not encountered any probs with .NET so far.
You could just be "not quite lucky"
Cheers
Sid
|
|
|
|
|
momer wrote:
unbearable restriction?
If we have to asked our users to install the .net framwork before run our application?
Would it not have been wise to investigate the .NET platform before development?
|
|
|
|
|
J4amieC wrote:
Would it not have been wise to investigate the .NET platform before development?
But that would have eaten in to valuable coding time. Gotta ship the project on time you know.
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
even if I install the .net framwork 1.1 package on Win2000,my C# application still cannt run on it.
I'm not sure what you are trying to say here. I develop C# 1.0 & 1.1. on both XP and Win 2000, I have never had any trouble running on 2000.
Specifically, what fails?
Gary
|
|
|
|
|
Hi,Gary,
At first thank you all!
Yes,you are right,I am a new hand with .net. I am very glad to know that it was my fault.
But one fact is that when I run my app on 2000,the following error occurs:
.NET Framework initialization error
C:\WINNT\Microsoft.NET\Framework\v1.0.3705\mscorwks.dll could not be loaded
That it is. I believe the trouble is not about the .net framework itself,but some other matter I not know at present.
So,I need your help.
momer
|
|
|
|
|
It would appear that your app was developed using one version of the .NET Framework and deployed under a different version.
What version of Visual Studio .NET are your using? What version of the .NET Framework is installed on the 2000 machine?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,Dave,
Thanks!
I know what the problem is. The version of Visual Studio.net is v1.0.3705,but the version of the .net framework installed on the 2000 is v1.1.
I am sorry I made a mistake.
Thank you again!
momer
|
|
|
|
|
hiii every body i have an apllication that consiste of a main form which have a main menu from which i open forms using (ShowDialog) every time i open the form and close it a new object created and the old one still in memory i noticed that using memory profiler i dispose the form and set it to null but it is still in memory this is because the form is still refrenced by a threadstart object which is refrenced by a thread object which i have create inside the form but it has finished i don't know why it is still refrence the form
please anybody know how can overcome this problem
dfds
|
|
|
|
|
Have you been disposing the dialog form once your done with it?
Form2 testDialog = new Form2();
testDialog.ShowDialog(this);
testDialog.Dispose();
If you don't .Dispose() the dialog, you'll keep creating instances that are never cleaned up. Read the docs[^] on Form.ShowDialog() for more information on how this method works.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi guys,
In VB the representation for hexedecimal is &H1 . How do you write this in C# . Please help. i'm running out of time.
|
|
|
|