Dev中GridControl如何获取多选的行的值

name_hq 2009-10-11 10:31:31
Dev中GridControl如何获取多选的行的值,
多选行是哪个时间
...全文
2353 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
huaxialonger 2012-06-04
  • 打赏
  • 举报
回复
gvDownDisturbCell.GetSelectedRows()
这样得到了选中的行,怎么取到每一行的值啊
wzm12349 2011-12-26
  • 打赏
  • 举报
回复
我想问,你们用的那个dev是什么版本的,我用的怎么是xpf.gridControl的啊(wpf)
zl34589 2011-07-28
  • 打赏
  • 举报
回复
leemans 2009-10-11
  • 打赏
  • 举报
回复


字数补丁.exe
name_hq 2009-10-11
  • 打赏
  • 举报
回复
gvDownDisturbCell.GetSelectedRows()
获取选中的所有行的Index
终于找到了,谢谢大家,
knotchen 2009-10-11
  • 打赏
  • 举报
回复
狂顶!!!!!!!!!!!!!!!!!闪开!
mythad 2009-10-11
  • 打赏
  • 举报
回复
jf
dqw120 2009-10-11
  • 打赏
  • 举报
回复
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.PopulateColumns();
else {
string[] fieldNames = new string[] {"ProductID", "ProductName", "QuantityPerUnit", "UnitPrice"};
DevExpress.XtraGrid.Columns.GridColumn column;
view.Columns.Clear();
for (int i = 0; i < fieldNames.Length; i++) {
column = view.Columns.Add(fieldNames[i]);
column.VisibleIndex = i;
}
}
GridColumn主要属性
Property Description GridColumn.Name 设计时定义的列名 GridColumn.FieldName 绑定到的数据源中的列名 GridColumn.AbsoluteIndex 在grid中的绝对位置索引 GridColumn.ColumnHandle 指定关联数据源列名的标识,它不一定是唯一的,因为一个数据源列可以关联到一个Grid中的多个列.

手动创建Band
// obtaining the main view and clearing its bands collection
BandedGridView view = gridControl1.MainView as BandedGridView;
view.Bands.Clear();
// creating the bands layout
GridBand bandGeneral = view.Bands.Add("General Info");
GridBand bandTechnical = view.Bands.Add("Technical Info");
GridBand bandEngine = bandTechnical.Children.Add("Engine Info");
GridBand bandTransmission = bandTechnical.Children.Add("Transmission Info");
// assigning columns to bands
colTrademark.OwnerBand = bandGeneral;
colModel.OwnerBand = bandGeneral;
colLiter.OwnerBand = bandEngine;
colCylinders.OwnerBand = bandEngine;
colSpeedCount.OwnerBand = bandTransmission;
colTransmission.OwnerBand = bandTransmission;


如何定位和查找指定列显示值的行(注意是列的实显示值,而不是关联数据源列值)
using DevExpress.XtraGrid.Views.base;
using DevExpress.XtraGrid.Columns;
// ...

string searchText = "Japan";
// obtaining the focused view
ColumnView view = (ColumnView)gridControl1.FocusedView;
// obtaining the column bound to the Country field
GridColumn column = view.Columns["Country"];
if(column != null) {
// locating the row
//如果用数据源中的列值,请用ColumnView.LocateByValue
int rhFound = view.LocateByDisplayText(view.FocusedRowHandle + 1, column, searchText);
// focusing the cell
if(rhFound != GridControl.InvalidRowHandle) {
view.FocusedRowHandle = rhFound;
view.FocusedColumn = column;
}
}


另一个查找示例
DevExpress.XtraGrid.Views.base.ColumnView view = gridControl1.MainView as DevExpress.XtraGrid.Views.base.ColumnView;
view.BeginUpdate();
try {
int rowHandle = 0;
DevExpress.XtraGrid.Columns.GridColumn col = view.Columns["Category"];
while(true) {
// locating the next row
rowHandle = view.LocateByValue(rowHandle, col, "SPORTS");
// exiting the loop if no row is found
if (rowHandle == DevExpress.XtraGrid.GridControl.InvalidRowHandle)
break;
// perform specific operations on the row found here
// ...
rowHandle++;
}
} finally { view.EndUpdate(); }

name_hq 2009-10-11
  • 打赏
  • 举报
回复
developer Express
PandaIT 2009-10-11
  • 打赏
  • 举报
回复
DEV是什么东东?

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

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

试试用AI创作助手写篇文章吧