很重要!!!Dev爲了區分winform的命名,會把一些新添加的屬性放在Properties對象裏!!找不到想要的屬性,記獲得裏面找找哦!bash
在這裏假設咱們的數據源是db.List(),在這裏我主要講述關於數據源綁定的方式。學習
!!下拉框的綁定須要三個:數據源,顯示值,隱藏值this
this.comboBox.DisplayMember="DisplayName";//數據源字段名稱【顯示值】
this.comboBox.ValueMember = "ValueName";//數據源字段名稱【隱藏值】
this.comboBox.DataSource=db.toList();//綁定數據源
複製代碼
!!前者沒辦法綁定數據源,只能經過遍歷的方式去添加數據,後者能夠綁定數據源,且功能強大!!很重要!!!Dev爲了區分winform的命名,會把一些新添加的屬性放在Properties對象裏!!找不到想要的屬性,記獲得裏面找找哦!spa
this.comboBoxEdit1.Properties.Items.Add("請選擇");
this.comboBoxEdit1.Properties.Items.Add("中國");
this.comboBoxEdit1.Properties.Items.Add("美國");
複製代碼
this.lookUpEdit1.Properties.DisplayMember ="DisplayName";//數據源字段名稱【顯示值】
this.lookUpEdit1.Properties.ValueMember = "ValueName";//數據源字段名稱【隱藏值】
this.lookUpEdit1.Properties.DataSource = db.toList();//綁定數據源
複製代碼
那麼這個到底強大在哪裏呢??它能夠顯示更多的字段,而不是在侷限於一個顯示字段。3d
MessageBox.Show("內容");
複製代碼
XtraMessageBox.Show("內容");
複製代碼
this.alertControl1.Show(this,"提示","您有一封消息");//this當前窗體,「提示」標題,「您有一封消息」內容
複製代碼
這個沒啥說的類,在須要的控件上綁定一下就行了code
給窗口添加一個點擊事件 orm
private void XtraForm3_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)//若是點擊爲右鍵
{
//激活右鍵菜單
//new Point(Cursor.Position.X,Cursor.Position.Y)鼠標所在焦點
this.popupMenu1.ShowPopup(new Point(Cursor.Position.X, Cursor.Position.Y));
}
}
複製代碼
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
//獲取當前點中單元格的值
string content = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
//獲取當前選中行數據
=var data = this.dataGridView1.Rows[e.RowIndex].DataBoundItem;
MessageBox.Show(content);
}
複製代碼
在窗體加載事件,設置cdn
//設置爲整行選中
this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
複製代碼
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
//獲取當前點中單元格的值
string content = this.dataGridView1.SelectedRows[0].Cells[e.ColumnIndex].Value.ToString();
//獲取當前選中行數據
var data = this.dataGridView1.SelectedRows[0].DataBoundItem;
MessageBox.Show(content);
}
複製代碼
private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
{
//焦點所在的數據
string content = this.gridView1.GetFocusedValue().ToString();
//焦點所在的數據行
var data = this.gridView1.GetFocusedRow();
MessageBox.Show(content);
}
複製代碼
學習要一步一步來,一步吃不成大胖子!對象