當前位置: 首頁>>代碼示例>>C#>>正文


C# DataGrid.IsSelected方法代碼示例

本文整理匯總了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);
		}
開發者ID:hindlemail,項目名稱:mono,代碼行數:94,代碼來源:ThemeWin32Classic.cs

示例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;
        }
開發者ID:slgrobotics,項目名稱:QuakeMap,代碼行數:14,代碼來源:DlgWaypointsManager.cs

示例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;
        }
開發者ID:slgrobotics,項目名稱:QuakeMap,代碼行數:13,代碼來源:DlgCustomMapsManager.cs

示例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;
        }
開發者ID:slgrobotics,項目名稱:QuakeMap,代碼行數:39,代碼來源:DlgWaypointsManager.cs


注:本文中的System.Windows.Forms.DataGrid.IsSelected方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。