comboBox中添加行
1.1、comboBox1.Items.Add("项目1");
1.2、ComboBoxItem cb = new ComboBoxItem() { Content="123",IsSelected=true,Tag="1"};
comboBox1.Items.Add(cb);
注意:使用ComboBoxItem 需要添加using System.Windows.Controls;
1.3 利用tag属性记录listmodel
public void loadSensorSmallTypeCmb(DevComponents.DotNetBar.Controls.ComboBoxEx ComboBox1)
{
List<DB.Model.m_SensorType> modelList = new List<DB.Model.m_SensorType>();
modelList = (new DB.BLL.m_SensorType()).GetModelList("i_Flag=0");
foreach (DB.Model.m_SensorType item in modelList)
{
DevComponents.DotNetBar.ComboBoxItem cmbitem = new DevComponents.DotNetBar.ComboBoxItem();
cmbitem.Tag = item;
cmbitem.Text = item.vc_Name;
cmbitem.Name = item.vc_Code.ToString();
ComboBox1.Items.Add(cmbitem);
}
string strSensorSmallType = Global.Params.ConfigModel.SystemConfig.mSensorSmallType;
foreach(DevComponents.DotNetBar.ComboBoxItem item in ComboBox1.Items)
{
if (strSensorSmallType == item.Name)
{
ComboBox1.SelectedItem=item;
break;
}
}
}
取值: string SensorSmallType = ((DevComponents.DotNetBar.ComboBoxItem)cmbSensorSmallType.SelectedItem).Name;
2、listview中添加行
this.listView1.Items.Clear();
private void LoadBill()
{
try
{
this.listView1.Items.Clear();
DataSet dst = DBOperater.SearchAllSMS_Employee();
for (int i = 0; dst != null && i < dst.Tables[0].Rows.Count; i++)
{
ListViewItem lvi = new ListViewItem(new string[] {(i+1).ToString (),
dst.Tables[0].Rows[i]["vc_ID"].ToString(),
dst.Tables[0].Rows[i]["vc_Name"].ToString(),
dst.Tables[0].Rows[i]["vc_Sex"].ToString(),
dst.Tables[0].Rows[i]["vc_Telephone"].ToString(),
dst.Tables[0].Rows[i]["vc_Department"].ToString(),
// dst.Tables[0].Rows[i]["m_dCreateTime"].ToString(),
dst.Tables[0].Rows[i]["vc_Remark"].ToString()});
lvi.Tag = dst.Tables[0].Rows[i]["vc_AutoID"].ToString();
// lvi.Tag = Convert.ToInt32(dst.Tables[0].Rows[i]["m_cRFID"]);
this.listView1.Items.Add(lvi);
}
}
catch (Exception ex)
{
DBOperater.LogWriter("SMS.Views.LoadBill error:" + ex.Message);
}
}
3、DataGridView中添加带tag的行
DataGridViewRow dr = new DataGridViewRow();
private void LoadBill()
{
try
{
dgvCustomer.Rows.Clear();
DataSet dst = DBOperater.SearchAllSMS_Employee();
for (int i = 0; dst != null && i < dst.Tables[0].Rows.Count; i++)
{
DataGridViewRow dr = new DataGridViewRow();
foreach (DataGridViewColumn c in dgvCustomer.Columns) //DataGridViewTextBoxCell)
{
dr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
}
dr.Cells[0].Value = (i + 1).ToString();
dr.Cells[1].Value = dst.Tables[0].Rows[i]["vc_ID"].ToString();
dr.Cells[2].Value = dst.Tables[0].Rows[i]["vc_Name"].ToString();
dr.Cells[3].Value = dst.Tables[0].Rows[i]["vc_Sex"].ToString();
dr.Cells[4].Value = dst.Tables[0].Rows[i]["vc_Department"].ToString();
dr.Cells[5].Value = dst.Tables[0].Rows[i]["vc_Telephone"].ToString();
dr.Cells[6].Value = dst.Tables[0].Rows[i]["vc_Remark"].ToString();
dr.Tag = dst.Tables[0].Rows[i]["vc_AutoID"].ToString();
this.dgvCustomer.Rows.Add(dr);
}
kryptonHeaderGroup2.ValuesSecondary.Heading = "当前记录: " + dgvCustomer.Rows.Count.ToString() + " 条";
}
catch (Exception ex)
{
DBOperater.LogWriter("SMS.Views.LoadBill SearchAllSMS_Employee error:" + ex.Message);
}
}
private void LoadAll()
{
List<DB_MinePressure.Model.m_Sensor> lstSensor = getSenserList();
dgvList.Rows.Clear();
int iIndex = 0;
foreach (DB_MinePressure.Model.m_Sensor item in lstSensor)
{
iIndex = dgvList.Rows.Add(dgvList.Rows.Count + 1, item.vc_Code, item.vc_Name,item.vc_Memo, item.ID);
dgvList.Rows[iIndex].Tag = item;
}
dgvList.ClearSelection();
for (int i = 0; i < dgvList.Columns.Count; i++)
{
dgvList.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
}
btnRightState.Text = "共" + lstSensor.Count.ToString() + "条记录";
}
取值: string id = ((DB_MinePressure.Model.m_Sensor)dgvList.SelectedRows[i].Tag).sensorTypeID.ToString();