弹出页面
主页面(FrmIn) FrmSelectEr frmSelect = new FrmSelectEr();
frmSelect.Owner = this;
frmSelect.ShowDialog();
弹出页面(frmSelect) 获取主页面控件值
FrmIn Frmin = (FrmIn)this.Owner;
Frmin.T_C_Name.Text ="XXX";
datagridview和listview 获取选中行,第一例的值
listview : list.SelectedItems[0].SubItems[0].Text;
datagridview:dataGridView1.SelectedRows[0].Cells[0].Value.ToString()
弹出确认框
if (MessageBox.Show("是否真的要修改该房间信息? ", "确定操作 ", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
{ xxxxx }
listview 赋值
public void databind(string SelectSQL)
{
list.Items.Clear();
DataSet ds = bll_customer.GetList(SelectSQL);
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
ListViewItem lvt = new ListViewItem(ds.Tables[0].Rows[i]["C_ID"].ToString().Trim());
lvt.SubItems.Add(ds.Tables[0].Rows[i]["C_Name"].ToString().Trim());
lvt.SubItems.Add(ds.Tables[0].Rows[i]["C_Sex"].ToString().Trim());
lvt.SubItems.Add(ds.Tables[0].Rows[i]["C_Money"].ToString().Trim());
lvt.SubItems.Add(ds.Tables[0].Rows[i]["C_dengjiTime"].ToString().Trim());
list.Items.Add(lvt);
}
}
}
=================
datagivdview赋值
public void databind()
{
DataSet ds_room = bll_room.GetAllList();
ds_room.Tables[0].Columns.Add();
ds_room.Tables[0].Columns.Add();
for (int i = 0; i < ds_room.Tables[0].Rows.Count; i++)
{
DataColumn dc = new DataColumn();
RoomFee rf = bll_RoomType.GetModel(ds_room.Tables[0].Rows[i]["RF_ID"].ToString());
ds_room.Tables[0].Rows[i][5] = rf.RF_Name.Trim();
ds_room.Tables[0].Rows[i][6] = rf.RF_Money.ToString();
}
dataGridViewX1.DataSource = ds_room.Tables[0];
dataGridViewX1.Columns[0].HeaderText = "房间号";
dataGridViewX1.Columns[1].Visible = false;
dataGridViewX1.Columns[2].HeaderText = "在住人数";
dataGridViewX1.Columns[3].HeaderText = "状态";
dataGridViewX1.Columns[4].HeaderText = "房间备注";
dataGridViewX1.Columns[5].HeaderText = "房间类别";
dataGridViewX1.Columns[6].HeaderText = "房间价格";
}
====-
listview 双击单元格事件
private void list_DoubleClick(object sender, EventArgs e)
{
if (list.SelectedItems.Count == 0) return;
FrmIn Frmin = (FrmIn)this.Owner;
if (Frmin == null)
{
return;
}
Frmin.T_C_Name.Text = list.SelectedItems[0].SubItems[1].Text;
Frmin.T_C_ID.Text = list.SelectedItems[0].SubItems[0].Text;
this.Close();
}
=====================
datagridview 鼠标单击事件,给textbox赋值
private void dataGridViewX1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
buttonX1.Enabled = false;
T_R_No.Text = dataGridViewX1.Rows[e.RowIndex].Cells[0].Value.ToString();
C_RoomType.SelectedText = dataGridViewX1.Rows[e.RowIndex].Cells[3].Value.ToString();
C_RoomType.SelectedValue = dataGridViewX1.Rows[e.RowIndex].Cells[1].Value.ToString();
T_R_mark.Text = dataGridViewX1.Rows[e.RowIndex].Cells[4].Value.ToString();
// T_RF_Num.Text = roomfee.RF_num.ToString(); ;
}
======================
contextMenuStrip 控件 右键快捷方式
private void listViewEx1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right && listViewEx1.SelectedItems.Count == 1)
{
contextMenuStrip1.Show(MousePosition);
}
}
=======================
窗体第一次出现位置
窗体的StarPosition属性值为centerscreen就能居中显示 ===========================
1. 常用属性设置
-外观 FullRowSelect True //选中整行
GridLines True //显示网格线
View Details
2. 选中整行触发的事件
ItemSelectionChanged
==双击单元格事件
3. 添加元素
ListViewItem li = new ListViewItem();
li.SubItems[0].Text = ".....";
li.SubItems.Add(...);
......
listView1.Items.Add(li);
4. 点击ListView列表头进行排序
private void listView1_ColumnClick(object sender, ColumnClickEventArgs e)
{
if (listView1.ListViewItemSorter == null)
listView1.ListViewItemSorter = new ListViewItemComparer(e.Column);
else
{
ListViewItemComparer comparer = listView1.ListViewItemSorter as ListViewItemComparer;
if (comparer.SortColumn == e.Column)
{
if (comparer.Order == SortOrder.Ascending)
comparer.Order = SortOrder.Descending;
else
comparer.Order = SortOrder.Ascending;
listView1.Sort();