1 实现iframe框架的效果使用splitContainer,分左右分割。
2 动态创建LinkLable并触发其LinkChecked事件:
for (int i = 0; i < n; i++)
{
LinkLabel lb = new LinkLabel();
lb.Text += dtGF.Rows[i]["cCode"].ToString();
panelremin.Controls.Add(lb);
lb.LinkClicked += new LinkLabelLinkClickedEventHandler(this.ButtonArray_OnClick);
lb.Dock = DockStyle.Top;//控件的顺序
}
private void ButtonArray2_OnClick(object sender, LinkLabelLinkClickedEventArgs e)
{ LinkLabel l_1 = (LinkLabel)sender;
FormDriverinfo formbusinfo = new FormDriverinfo(l_1.Text);
formbusinfo.ShowDialog();
}
3 listview绑定
private void Bind() {
this.listViewRight.Columns.Add("车牌号", 80, HorizontalAlignment.Center);
this.listViewRight.Columns.Add("状态", 80, HorizontalAlignment.Center);
this.listViewRight.Columns.Add("驾驶员", 80, HorizontalAlignment.Center);
listViewRight.FullRowSelect = true;
listViewRight.View = View.Details;
listViewRight.GridLines = true;//显示网格线
}
try
{
this.listViewRight.Clear();
Bind();
DataTable dt = CarManage.GetStateList("");
if (dt != null)
{
int count = dt.Rows.Count;
string[] str = new string[4];
for (int i = 0; i < count; i++)
{
SaveValues en = new SaveValues();
str[0] = dt.Rows[i]["cCode"].ToString();
str[1] = dt.Rows[i]["cStatusName"].ToString();
str[2] = dt.Rows[i]["cDriverName"].ToString();
str[3] = dt.Rows[i]["AutoID"].ToString();
ListViewItem item = new ListViewItem(str, 4);
this.listViewRight.Items.Add(item);
}
}
} catch (Exception ex)
{
MessageBox.Show("系统出现异常。异常信息:" + ex.ToString());
}
这样绑定的话即第四列不显示出来
4 得到listview选中行某列的值
if (listViewRight.SelectedItems.Count > 0)//判断必须,不然出现异常
{
System.Windows.Forms.ListViewItem.ListViewSubItem myItem = new System.Windows.Forms.ListViewItem.ListViewSubItem();
myItem = listViewRight.SelectedItems[0].SubItems[1];
string code = myItem.Text;
....
}
5 自己常用的winform传值
1>
Form1.cs
private void TSMInfo_Click(object sender, EventArgs e)
{
FormBusinfo formBusInfo = new FormBusinfo(code);
formBusInfo.ShowDialog();
}
FormInBus.cs
在FormInBus窗体定义CarID
public FormInBus(int carid)
{
InitializeComponent();
CarID = carid;
}
把父窗体值传入子窗体
2>
FormInsurancetable .cs
private void TSMInfo_Click(object sender, EventArgs e)
{
AddFees addfees = new AddFees();
addfees.Owner = this;
addfees.ShowDialog();
}
public string carnum {
get { return TxtNumBusNum.Text; }
set { TxtNumBusNum.Text = value; }
}
AddFees .cs
FormInsurancetable insurance = (FormInsurancetable)this.Owner;
insurance .aa=youvalue
即把子窗体的youvalue传入父窗体文本框
把父窗体的文本框控件设为public属性,也可在在窗体中直接访问文本框的insurance.Text得到父窗体文本框的值
6 winform中datagridview
this.dataGridView1.DataSource = dt.DefaultView;
不想aspnet 需要DataBind();
7 winform中treeView
绑定: public void InitTvArea(){
try
{
this.treeView1.Nodes.Clear();
DataTable dt = BaseManage.DriverList();
foreach (DataRow row in dt.Rows)
{
TreeNode childNode = new TreeNode();
childNode.Text = row["cName"].ToString();
childNode.Tag = row["cCode"].ToString();
this.treeView1.Nodes.Add(childNode);
}
}
catch (Exception ex)
{
MessageBox.Show("系统出现异常。异常信息:"+ex.ToString());
}
}
选中特定节点:
if (node.Text == "保养类别")
treeView1.SelectedNode = node;
选中事件:
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
switch(treeView1.SelectedNode.Text)
{
....
}
}