本人菜鸟啊,最好能QQ1261017015
<
本人菜鸟啊,最好能QQ1261017015
<
我把全部代码给你贴上,
新建一个form程序,向里面添加3个控件 2个comboBox控件,分别命名为comboBox1和comboBox2,在新建一个lable控件lable2
我也是新手,不会高难的,如果你是初学,我感觉我写的比较易于理解
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//想comboBox中添加数据的两种方法,可能还有更多方法我知道2个
//第一种:像第一个comboBox中添加1到5的int类型数据
for (int i=1;i<=5;i++)
this.comboBox1.Items.Add(i);
//第二种:向comboBox数组数据
comboBox2.Items.AddRange(new object[] { 5,4,3,2,1});
}
//我自己顶一个计算的方法,但是也可以不定义,直接在comboBox的选择方法中自己定义
private void operation(int operation1,int operation2)
{
int sum;
sum =operation1 * operation2;
label2.Text =sum.ToString() ;
}
//comboBox1列表中点击选择后执行方法
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox2.Text.Length>0) //做一个简单判断,避免另一个comboBox为空引起的错误
operation(Convert.ToInt32(comboBox1.Text) , Convert.ToInt32(comboBox2.Text) );
}
//comboBox2列表中点击选择后执行方法
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.Text.Length > 0) //做一个简单判断,避免另一个comboBox为空引起的错误
operation(Convert.ToInt32(comboBox1.Text), Convert.ToInt32(comboBox2.Text));
}
}
}
请高手直接弄个代码
在form1 中 建 combobox1(有5个选项,每个选项代表一个值) combobox2(同一)
在label1中显示 combobox1*combobox2的值
要全部的代码
MSDN
代码么?正好闲着,写了一个。
你新建控制台应用程序,粘贴如下代码到你的program.cs即可。
using System;
using System.Drawing;
using System.Windows.Forms;
namespace CSharpConsole06
{
class Program
{
static void Main(string[] args)
{
Application.Run(new MyForm());
Console.ReadKey();
}
public class MyForm : Form
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
ComboBox c1 = new ComboBox();
ComboBox c2 = new ComboBox();
for (int i = 0; i < 100; i++)
{
c1.Items.Add(i.ToString());
c2.Items.Add(i.ToString());
}
c1.SelectedIndex = 1;
c2.SelectedIndex = 1;
c1.DropDownStyle = ComboBoxStyle.DropDownList;
c2.DropDownStyle = ComboBoxStyle.DropDownList;
c2.Left = c1.Width + 1;
Label lb = new Label();
lb.Top = c1.Height + 1;
Button btn = new Button();
btn.Text = "Click me";
btn.Location = new Point(0, 200);
btn.Click += (EventHandler)delegate { lb.Text = (int.Parse(c1.Text) * int.Parse(c2.Text)).ToString(); };
this.Controls.Add(c1);
this.Controls.Add(c2);
this.Controls.Add(lb);
this.Controls.Add(btn);
}
}
}
}
忘说了,需要项目上右键,选择添加引用,添加2个文件引用:
System.Drawing.dll
System.Windows.Forms.dll
ComboBox1.DataSource=dataset.Tables[0];
ComboBox1.DisplayMember="NAME";
ComboBox1.ValueMember="ID";
DataRowView drv = (DataRowView)comboBox1.SelectedItem;
DataRowView drv2 = (DataRowView)comboBox1.SelectedItem;
Label.Text== Convert.ToInt32(drv.Row["id"])*Convert.ToInt32(drv2.Row["id"]);
http://msdn.microsoft.com/zh-cn/library/4ex92czb(v=VS.80).aspx
谢各位啦
比如说你想用它选择“部门”对象,首先做一个返回数据实体的BLL方法,例如:
public static List<部门> Get全部部门
{
return 查询数据库返回全部部门对象();
}
bindingsource的作用,在于它是一个通用的数据源。多个控件可以绑定到它,当它改变时会通知多个关联的控件,而任意一个关联控件通常也可以自动化地将用户操作重新设置到bindingsource的各种属性(例如Position属性等等),属性的改变又会再传递到关联的其它控件.....一个bindingsource与多个控件的双向绑定控制流程全都封装好了。
“如果你是初学,我感觉我写的比较易于理解”
这可能是个错觉。平板手推车比大卡车更易于理解,但是如果你要开个矿山,使用卡车肯定比使用手推车重要。
组合框,比较好用,传统的用户控件
这个帖子很有意思
新手,支持一下了,代码都有了
顶一下~~
这个还是要自己用才真正晓得,MSDN,看书,看视频都可以,做两个小例子用下就明白了