日期:2014-05-18  浏览次数:21151 次

Dev中GridControl如何获取多选的行的值
Dev中GridControl如何获取多选的行的值,
多选行是哪个时间

------解决方案--------------------
DEV GridControl(摘自baobao博客)2008-03-26 09:06去掉GridControl控件上面的Drag a column header here to group by that columnOptions\OptionsView\ShowGroupPanel True----->False提交当前行的修改using DevExpress.XtraGrid;using DevExpress.XtraGrid.Views.base;using System.Data.Common;//...public void UpdateDatasource(GridControl grid) { //Save the latest changes to the bound DataTable ColumnView view = (ColumnView)grid.FocusedView;
view.CloseEditor();
if(!view.UpdateCurrentRow()) return;
//Update the database's Suppliers table to which oleDBDataAdapter1 is connected
DoUpdate(oleDbDataAdapter1, dataSet11.Tables["Suppliers"]);
//Update the database's Products table to which the oleDbDataAdapter2 is connected
DoUpdate(oleDbDataAdapter2, dataSet11.Tables["Products"]);
}public void DoUpdate(DbDataAdapter dataAdapter, System.Data.DataTable dataTable) {
try {
dataAdapter.Update(dataTable);
} catch(Exception ex) {
MessageBox.Show(ex.Message);
}
}
 
 
从非绑定数据源得到数据
private void Form1_Load(object sender, System.EventArgs e) 
{ // Create an unbound column.
GridColumn unbColumn = gridView1.Columns.Add("Total");
unbColumn.VisibleIndex = gridView1.Columns.Count;
unbColumn.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
// Disable editing.
unbColumn.OptionsColumn.AllowEdit = false;
// Specify format settings.
unbColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
unbColumn.DisplayFormat.FormatString = "c";
// Customize the appearance settings.
unbColumn.AppearanceCell.BackColor = Color.LemonChiffon;
} // Returns the total amount for a specific row.
decimal getTotalValue(ColumnView view, int rowHandle) {
decimal unitPrice = Convert.ToDecimal(view.GetRowCellValue(rowHandle, "UnitPrice"));
decimal quantity = Convert.ToDecimal(view.GetRowCellValue(rowHandle, "Quantity"));
decimal discount = Convert.ToDecimal(view.GetRowCellValue(rowHandle, "Discount"));
return unitPrice * quantity * (1 - discount);
} // Provides data for the Total column.
private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.base.CustomColumnDataEventArgs e) {
if(e.Column.FieldName == "Total" && e.IsGetData) e.Value = getTotalValue(sender as ColumnView, e.RowHandle);
}
 
 
运行时绑定到实现Ilist接口的数据源
public class Record {
int id, age;
string name;
public Record(int id, string name, int age) {
this.id = id;
this.name = name;
this.age = age;
}
public int ID { get { return id; } }
public string Name {
get { return name; }
set { name = value; }
}
public int Age {
get { return age; }
set { age = value; }
}
}
ArrayList listDataSource = new ArrayList();
listDataSource.Add(new Record(1, "Jane", 19));
listDataSource.Add(new Record(2, "Joe", 30));
listDataSource.Add(new Record(3, "Bill", 15));
listDataSource.Add(new Record(4, "Michael", 42));
gridControl1.DataSource = listDataSource;
gridControl1.MainView.PopulateColumns();
自定义列:
[C#] 
DevExpress.XtraGrid.Views.base.ColumnView view = gridControl1.MainView as DevExpress.XtraGrid.Views.base.ColumnView;
DialogResult answer = MessageBox.Show("Do you want to create columns for all fields?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (answer == DialogResult.Yes)
view.PopulateCol