怎样在DataGrid中加入checkBox

xhjdxx 2003-07-18 10:04:01
如上
...全文
19 3 打赏 收藏 举报
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
雪狼1234567 2003-07-18
  • 打赏
  • 举报
回复
// Step 1. Derive a custom column style from DataGridTextBoxColumn

// a) add a ComboBox member

// b) track when the combobox has focus in Enter and Leave events

// c) override Edit to allow the ComboBox to replace the TextBox

// d) override Commit to save the changed data





// Step 2 - Use the combo column style

// Add 1 col with combo style

DataGridComboBoxColumn ComboTextCol = new DataGridComboBoxColumn();

ComboTextCol.MappingName = "custCity";

ComboTextCol.HeaderText = "Customer Address";

ComboTextCol.Width = 100;

ts1.GridColumnStyles.Add(ComboTextCol);



// Step 3 - Additional setup for Combo style

// a) make the row height a little larger to handle minimum combo height

ts1.PreferredRowHeight = ComboTextCol.ColumnComboBox.Height + 3;

// b) Populate the combobox somehow. It is a normal combobox, so whatever...

ComboTextCol.ColumnComboBox.Items.Clear();

ComboTextCol.ColumnComboBox.Items.Add("Chicago");

ComboTextCol.ColumnComboBox.Items.Add("Corvallis");

ComboTextCol.ColumnComboBox.Items.Add("Denver");

ComboTextCol.ColumnComboBox.Items.Add("Great Falls");

ComboTextCol.ColumnComboBox.Items.Add("Kansas City");

ComboTextCol.ColumnComboBox.Items.Add("Los Angeles");

ComboTextCol.ColumnComboBox.Items.Add("Raleigh");

ComboTextCol.ColumnComboBox.Items.Add("Washington");



// c) set the dropdown style of the combo...

ComboTextCol.ColumnComboBox.DropDownStyle = ComboBoxStyle.DropDownList;


xhjdxx 2003-07-18
  • 打赏
  • 举报
回复
参考如下代码:
// Step 1. Derive a custom column style from DataGridTextBoxColumn

// a) add a ComboBox member

// b) track when the combobox has focus in Enter and Leave events

// c) override Edit to allow the ComboBox to replace the TextBox

// d) override Commit to save the changed data





// Step 2 - Use the combo column style

// Add 1 col with combo style

DataGridComboBoxColumn ComboTextCol = new DataGridComboBoxColumn();

ComboTextCol.MappingName = "custCity";

ComboTextCol.HeaderText = "Customer Address";

ComboTextCol.Width = 100;

ts1.GridColumnStyles.Add(ComboTextCol);



// Step 3 - Additional setup for Combo style

// a) make the row height a little larger to handle minimum combo height

ts1.PreferredRowHeight = ComboTextCol.ColumnComboBox.Height + 3;

// b) Populate the combobox somehow. It is a normal combobox, so whatever...

ComboTextCol.ColumnComboBox.Items.Clear();

ComboTextCol.ColumnComboBox.Items.Add("Chicago");

ComboTextCol.ColumnComboBox.Items.Add("Corvallis");

ComboTextCol.ColumnComboBox.Items.Add("Denver");

ComboTextCol.ColumnComboBox.Items.Add("Great Falls");

ComboTextCol.ColumnComboBox.Items.Add("Kansas City");

ComboTextCol.ColumnComboBox.Items.Add("Los Angeles");

ComboTextCol.ColumnComboBox.Items.Add("Raleigh");

ComboTextCol.ColumnComboBox.Items.Add("Washington");



// c) set the dropdown style of the combo...

ComboTextCol.ColumnComboBox.DropDownStyle = ComboBoxStyle.DropDownList;


TheAres 2003-07-18
  • 打赏
  • 举报
回复
5.11 How can I put a checkbox in a column of my DataGrid?
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q754q
相关推荐
发帖
C#

10.8w+

社区成员

.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
帖子事件
创建了帖子
2003-07-18 10:04
社区公告

让您成为最强悍的C#开发者