本文整理汇总了C#中System.Windows.Forms.DataGrid.IsSelected方法的典型用法代码示例。如果您正苦于以下问题:C# DataGrid.IsSelected方法的具体用法?C# DataGrid.IsSelected怎么用?C# DataGrid.IsSelected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.DataGrid
的用法示例。
在下文中一共展示了DataGrid.IsSelected方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DataGridPaintRowContents
public override void DataGridPaintRowContents (Graphics g, int row, Rectangle row_rect, bool is_newrow,
Rectangle clip, DataGrid grid)
{
Rectangle rect_cell = new Rectangle ();
int col_pixel;
Color backcolor, forecolor;
Brush backBrush, foreBrush;
Rectangle not_usedarea = Rectangle.Empty;
rect_cell.Y = row_rect.Y;
rect_cell.Height = row_rect.Height;
if (grid.IsSelected (row)) {
backcolor = grid.SelectionBackColor;
forecolor = grid.SelectionForeColor;
} else {
if (row % 2 == 0) {
backcolor = grid.BackColor;
} else {
backcolor = grid.AlternatingBackColor;
}
forecolor = grid.ForeColor;
}
backBrush = ResPool.GetSolidBrush (backcolor);
foreBrush = ResPool.GetSolidBrush (forecolor);
// PaintCells at row, column
int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount;
DataGridCell current_cell = grid.CurrentCell;
if (column_cnt > 0) {
Region prev_clip = g.Clip;
Region current_clip;
for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) {
if (grid.CurrentTableStyle.GridColumnStyles[column].bound == false)
continue;
col_pixel = grid.GetColumnStartingPixel (column);
rect_cell.X = row_rect.X + col_pixel - grid.HorizPixelOffset;
rect_cell.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;
if (clip.IntersectsWith (rect_cell)) {
current_clip = new Region (rect_cell);
current_clip.Intersect (row_rect);
current_clip.Intersect (prev_clip);
g.Clip = current_clip;
Brush colBackBrush = backBrush;
Brush colForeBrush = foreBrush;
// If we are in the precise cell we are editing, then use the normal colors
// even if we are selected.
if (grid.is_editing && column == current_cell.ColumnNumber && row == current_cell.RowNumber) {
colBackBrush = ResPool.GetSolidBrush (grid.BackColor);
colForeBrush = ResPool.GetSolidBrush (grid.ForeColor);
}
if (is_newrow) {
grid.CurrentTableStyle.GridColumnStyles[column].PaintNewRow (g, rect_cell,
colBackBrush,
colForeBrush);
} else {
grid.CurrentTableStyle.GridColumnStyles[column].Paint (g, rect_cell, grid.ListManager, row,
colBackBrush,
colForeBrush,
grid.RightToLeft == RightToLeft.Yes);
}
current_clip.Dispose ();
}
}
g.Clip = prev_clip;
if (row_rect.X + row_rect.Width > rect_cell.X + rect_cell.Width) {
not_usedarea.X = rect_cell.X + rect_cell.Width;
not_usedarea.Width = row_rect.X + row_rect.Width - rect_cell.X - rect_cell.Width;
not_usedarea.Y = row_rect.Y;
not_usedarea.Height = row_rect.Height;
}
}
else {
not_usedarea = row_rect;
}
if (!not_usedarea.IsEmpty && clip.IntersectsWith (not_usedarea))
g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor),
not_usedarea);
}
示例2: GetSelectedRowsView
public ArrayList GetSelectedRowsView(DataGrid dataGrid)
{
ArrayList al = new ArrayList();
DataTable srcTable = ((DataView)dataGrid.DataSource).Table;
for(int i = 0; i < srcTable.Rows.Count; ++i)
{
if(dataGrid.IsSelected(i))
{
al.Add(i);
}
}
return al;
}
示例3: GetSelectedRows
public ArrayList GetSelectedRows(DataGrid dataGrid)
{
ArrayList al = new ArrayList();
for(int i = 0; i < ((DataSet)dataGrid.DataSource).Tables[0].Rows.Count; ++i)
{
if(dataGrid.IsSelected(i))
{
al.Add(i);
}
}
return al;
}
示例4: GetSelectedRowsDataView
// this one works for waypoints grid only so far, as columnId is specific to waypoints table.
public DataView GetSelectedRowsDataView(DataGrid dataGrid)
{
DataTable srcTable = ((DataView)dataGrid.DataSource).Table;
DataTable newTable = srcTable.Clone();
newTable.Clear();
for(int i=0; i < newTable.Columns.Count ;i++)
{
newTable.Columns[i].ReadOnly = false;
}
int columnId = 0;
for(int i = 0; i < srcTable.Rows.Count; ++i)
{
if(dataGrid.IsSelected(i))
{
int id = (int)dataGrid[i, columnId];
DataRow srcRow = null;
foreach(DataRow row in srcTable.Rows)
{
if((int)row["id"] == id)
{
srcRow = row;
break;
}
}
if(srcRow != null)
{
DataRow newRow = newTable.NewRow();
for(int j=0; j < srcRow.ItemArray.Length ;j++)
{
newRow[j] = srcRow[j];
}
newTable.Rows.Add(newRow);
}
}
}
return newTable.DefaultView;
}