comboBox,listview,DataGridView中添加Item
2012-03-16 21:58
381 查看
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();
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();
相关文章推荐
- DataGridView中添加combobox控件
- ListView里面添加Button之类可点击事件Item不可点击的处理方法
- 为ListView每个Item上面的按钮添加事件
- VB中给listview的item添加多行气泡式Tooltip
- 利用RecycleView实现类似ListView的Item点击,长按等操作事件以及点击后每一项在添加一个列表
- Android------Anndroid中ListView在划屏到底部的时候动态添加ListView的Item实现
- 为ListView每个Item上面的按钮添加事件
- ListView每个Item上面的组件添加事件
- ListView 动态删除添加Item方法
- android ListView item中添加checkbox之后点击无效的解决办法
- 分别使用simpleAdapter和baseAdapter为ListView的Item添加按钮响应事件
- Android ListView添加多种类型的ItemView
- 手动添加数据源时DataGridViewComboBoxCell值出问题解决方法
- DataGridView单元格ComboBox控件添加事件
- android中ListView在划屏到底部的时候动态添加ListView的Item实现
- listview如果添加的有Headview和Footview,onItemClick数值异常
- 动态添加删除ExpandableListView的item的例子
- 通过代码动态添加列表item实现列表(不使用listview列表)
- 实现类似listView中动态添加Item的功能
- 为ListView每个Item上面的按钮添加事件在Adapter中响应