|
comboBox1.SelectedValue.ToString() is Return Namespace name and Class name
|
|
|
|
|
You said you are using DataBase..
See the code bellow this is what I used :
namespace C_TestProject
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); ' Contains
}
private void Form1_Load(object sender, EventArgs e)
{
this.dB1TableAdapter.Fill(this.dbTestDataSet.DB1);
}
private void button1_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex >= 0)
MessageBox.Show(comboBox1.SelectedValue.ToString());
}
}
}
// code Inside InitializeComponent()
this.components = new System.ComponentModel.Container();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.button1 = new System.Windows.Forms.Button();
this.dbTestDataSet = new C_TestProject.DbTestDataSet();
this.dB1BindingSource = new System.Windows.Forms.BindingSource(this.components);
this.dB1TableAdapter = new C_TestProject.DbTestDataSetTableAdapters.DB1TableAdapter();
((System.ComponentModel.ISupportInitialize)(this.dbTestDataSet)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dB1BindingSource)).BeginInit();
this.SuspendLayout();
//
// comboBox1
//
this.comboBox1.DataSource = this.dB1BindingSource;
this.comboBox1.DisplayMember = "EmpName";
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(62, 29);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 21);
this.comboBox1.TabIndex = 0;
this.comboBox1.ValueMember = "ID";
//
// button1
//
this.button1.Location = new System.Drawing.Point(62, 90);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(121, 23);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// dbTestDataSet
//
this.dbTestDataSet.DataSetName = "DbTestDataSet";
this.dbTestDataSet.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;
//
// dB1BindingSource
//
this.dB1BindingSource.DataMember = "DB1";
this.dB1BindingSource.DataSource = this.dbTestDataSet;
//
// dB1TableAdapter
//
this.dB1TableAdapter.ClearBeforeFill = true;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(243, 229);
this.Controls.Add(this.button1);
this.Controls.Add(this.comboBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dbTestDataSet)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dB1BindingSource)).EndInit();
this.ResumeLayout(false);
|
|
|
|
|
Dear Sirs,
I use Visual Studio .NET 2005 (Framework 2.0)
I use Tree-Tier architecture approach in my project, and I use NHibernate.
I get data in the Data Layer from database and initialize object.
In View Layer;
First of all I determine ValueMember and DisplayMember for ComboBox
comboBox1.ValueMember = "id";
comboBox1.DisplayMember = "name";
And determine DataSource for ComboBox. I get data in IList fromat from Data Layer.
comboBox1.DataSource = XYZ; //XYZ is a IList
Now, ComboBox list name, its OK. My problem is I get id when I select any name from combobox.
**FOR EXAMPLE:
TEST_TABLE
ID Name Surname
-- ---- -------
3 Jack Black
4 Marry Green
5 John Wall
I fill combobox like this;
comboBox1.ValueMember = "id";
comboBox1.DisplayMember = "name";
comboBox1.DataSource = obj; //obj is IList
So, combobox filled and show "Name"s.
How can I get selected value's ID from combobox.
For example, if I select "Marry" on the combobox, how can I get "4"?
Note: This ways not solve my problem.
Int32 i = Convert.ToInt32(comboBox1.SelectedValue);
Int32 i = (Int32)comboBox1.SelectedValue;
int i = (int)comboBox1.SelectedValue;
string test = (string)comboBox1.SelectedValue;
string deneme = comboBox1.SelectedItem.ToString();
object o = comboBox1.SelectedValue;
DataRowView o = (DataRowView) comboBox1.SelectedValue;
Best Regards...
|
|
|
|
|
hi
i'm working on MessageBox button of Ok and Cancel.
i want to implement different code segments when Ok button is clicked and different code segments when Cancel button is clicked.
whichever button is clicked on the message box it always returns the same "true" value.
does anyone know how to access these returned value according to the button pressed??
|
|
|
|
|
You can try this.
http://msdn2.microsoft.com/en-us/library/system.windows.forms.dialogresult.aspx
|
|
|
|
|
try this........
If MessageBox.Show("klsdf", "sdf", MessageBoxButtons.OKCancel) = DialogResult.OK Then
MsgBox("ok")
Else
MsgBox("cancel")
End If
Parwej Back...............DON of Developer.......
Parwej Ahamad
g_parwez@rediffmail.com
|
|
|
|
|
C#
if(MessageBox.Show("abc", "def", System.Windows.Forms.MessageBoxButtons.OKCancel) == DialogResult.OK)
{
}
else
{
}
All the best,
Martin
|
|
|
|
|
The message box returns a DialogResult object (example result). by having condition like this
<br />
result.toString() == "Yes"<br />
result.toString() == "Ok"<br />
result.toString() == "Cancel"<br />
.....<br />
....<br />
..<br />
.<br />
this will let you know what button is clicked
|
|
|
|
|
Why should somebody compare the string instead of the enum value itselve?
|
|
|
|
|
why are you confused Martin
Because it is the same. No errors will happen and the same result will get back
|
|
|
|
|
If you write everything correct, but if not compiler will not tell you.
But again, why?
All the best,
MArtin
|
|
|
|
|
ok man i already said down that i was wrong and you were right
anyway thanks for the new info.
take care
|
|
|
|
|
(Next time it's your turn again)
All the best,
Martin
|
|
|
|
|
it's not the same..
comparing strings takes more resources than comparing integers (which enums are)..
life is study!!!
|
|
|
|
|
quiteSmart wrote: result.toString() == "Yes"
result.toString() == "Ok"
result.toString() == "Cancel"
You should compare the result directly with the members of the DialogResult enumeration, because it's less error-prone.
result == DialogResult.Yes
result == DialogResult.OK
result == DialogResult.Cancel
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
IT is the same man
no errors will happen
|
|
|
|
|
quiteSmart wrote: IT is the same man
no errors will happen
Sure, it will work, but what if Microsoft decides to change the return values of toString in the next framework version. Comparison with the enumeration members will still work, but your string comparison will not.
Furthermore, I wasn't refering to errors at runtime, but mainly to those made during development. If you have a typo in a string value, the code will compile fine, but it will not do what you expect it to do. If you have a typo in the identfiers of enumeration members, the compiler will complain, so the process of writing the code is less error-prone.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
It seems that you convinced me. I guess your totaly right. I will start using the enumeration from now on.
Thanks anyway
|
|
|
|
|
Stefan Troschütz wrote: Sure, it will work, but what if Microsoft decides to change the return values of toString in the next framework version. Comparison with the enumeration members will still work, but your string comparison will not.
Not just then, but what about foreign language OSes. Wouldn't they have localized button names?
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
But if you have a typo somewhere in your string the compiler won't tell you about it which he would do when using enumeration values.
Robert
|
|
|
|
|
Can I change the color of perticular cell in C# for DataGrid control.
I want to change the color of the cells which have numeric value below 100.
|
|
|
|
|
foreach (GridViewRow row in GridView1.Rows)
{
long cellValue = long.Parse(row.Cells[1].Text.ToString());
if (cellValue > 100)
{
row.Cells[1].BackColor = System.Drawing.Color.Red;
row.Cells[1].ForeColor = System.Drawing.Color.Blue;
}
}
Here Cells[1] 1 should be the index of the Column that you want to compare.
for(int i=0;i<500;i++)
Console.WriteLine("I Love C# \n");
|
|
|
|
|
But I am not using any WEB page , can I use (GridViewRow control ) for the desktop application aswell.
|
|
|
|
|
I want to learn how to create custom skinned GUIs like the ones we see
when using products like StyleXP or WindowBlinds.
I've just started with basic windows forms programming, and I'm finding
the default styles to be sucky.
What are the techniques of 'skinning' a window's form? (In Visual C++ 6
and in Visual C#) Will it vary depending on languages? as in VC++6 and
VC#?
A detailed explanation would be very helpful.
Thanks.
ASP - AJAX is SEXY. PERIOD.
|
|
|
|
|
A good place to start could possibly be to create a UserControl , override the OnPaint method and spam some GDI+
|
|
|
|