本文整理汇总了C#中System.Windows.Forms.DataGridViewCell类的典型用法代码示例。如果您正苦于以下问题:C# DataGridViewCell类的具体用法?C# DataGridViewCell怎么用?C# DataGridViewCell使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataGridViewCell类属于System.Windows.Forms命名空间,在下文中一共展示了DataGridViewCell类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getValueFromCell
public object getValueFromCell(DataGridViewCell cell)
{
object value = null;
switch (cell.ValueType.Name)
//need to do this because row.Cells["Value"].ValueType returns a string value for all cells
{
case "Boolean":
value = bool.Parse(cell.EditedFormattedValue.ToString());
break;
case "Byte":
value = byte.Parse(cell.EditedFormattedValue.ToString());
break;
case "List`1":
value = new List<String>(new[] { cell.EditedFormattedValue.ToString() });
break;
case "UInt32":
value = UInt32.Parse(cell.EditedFormattedValue.ToString());
break;
case "String":
value = cell.EditedFormattedValue.ToString();
break;
case "TraceType":
value = Enum.Parse(typeof(TraceType), cell.Value.ToString());
break;
default:
break;
}
return value;
}
示例2: Show
/// ------------------------------------------------------------------------------------
public void Show(DataGridViewCell cell, IEnumerable<string> items)
{
// This is sort of a kludge, but right before the first time the list is
// displayed, it's handle hasn't been created therefore the preferred
// size cannot be accurately determined and the preferred width is needed
// below. So to ensure the handle gets created, show then hide the drop-down.
if (!IsHandleCreated)
{
Size = new Size(0, 0);
_dropDown.Show(0, 0);
_dropDown.Close();
}
Items.Clear();
Items.AddRange(items.ToArray());
SelectedItem = cell.Value as string;
if (SelectedIndex < 0 && Items.Count > 0)
SelectedIndex = 0;
_associatedCell = cell;
int col = cell.ColumnIndex;
int row = cell.RowIndex;
Width = Math.Max(cell.DataGridView.Columns[col].Width, _listBox.PreferredSize.Width);
Height = (Math.Min(Items.Count, 15) * _listBox.ItemHeight) + Padding.Vertical + 2;
var rc = cell.DataGridView.GetCellDisplayRectangle(col, row, false);
rc.Y += rc.Height;
_dropDown.Show(cell.DataGridView.PointToScreen(rc.Location));
_listBox.Focus();
}
示例3: disableCell
public static void disableCell(DataGridViewCell cell)
{
cell.ReadOnly = true;
cell.Style.ForeColor = Color.DarkGray;
cell.Style.BackColor = Color.LightGray;
cell.Style.SelectionBackColor = Color.LightBlue;
}
示例4: PerformOnCells
/// <summary>
/// Perform a function on grid cells.
/// </summary>
/// <param name="startCell">Cell from which to start. Does not wrap to start.</param>
/// <param name="processStartCell">Whether to apply <see cref="function"/> to <see cref="startCell"/></param>
/// <param name="stopOnFirstAction">Whether to halt processing the first time <see cref="function"/> returns true</param>
/// <param name="function">Function to perform on the cell. Processing stops when this function returns true.</param>
/// <returns>Whether the function ever returned true.</returns>
public bool PerformOnCells(DataGridViewCell startCell, bool processStartCell, bool stopOnFirstAction, Func<DataGridViewCell, bool> function)
{
if (_grid == null || _grid.RowCount == 0 || _grid.ColumnCount == 0)
return false;
bool performed = false;
int initialRow = startCell == null ? 0 : startCell.RowIndex;
int initialCol = startCell == null ? 0 : startCell.ColumnIndex;
int startRow = initialCol == 0 ? initialRow : initialRow + 1;
for (int rowIndex = startRow; rowIndex < _grid.Rows.Count; rowIndex++)
{
DataGridViewRow row = _grid.Rows[rowIndex];
int startCol = (rowIndex == initialRow && !processStartCell && _grid.ColumnCount > 1) ? 1 : 0;
for (int colIndex = startCol; colIndex < row.Cells.Count; colIndex++)
{
DataGridViewCell cell = row.Cells[colIndex];
performed |= function(cell);
if (performed && stopOnFirstAction)
return true;
}
}
return performed;
}
示例5: Remove
public bool Remove(DataGridViewCell dataGridViewCell)
{
DataGridViewCellLinkedListElement element = null;
DataGridViewCellLinkedListElement headElement = this.headElement;
while (headElement != null)
{
if (headElement.DataGridViewCell == dataGridViewCell)
{
break;
}
element = headElement;
headElement = headElement.Next;
}
if (headElement.DataGridViewCell != dataGridViewCell)
{
return false;
}
DataGridViewCellLinkedListElement next = headElement.Next;
if (element == null)
{
this.headElement = next;
}
else
{
element.Next = next;
}
this.count--;
this.lastAccessedElement = null;
this.lastAccessedIndex = -1;
return true;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:31,代码来源:DataGridViewCellLinkedList.cs
示例6: CellInfo
public CellInfo(DataGridViewCell cell, DateTime monday)
{
int day = cell.ColumnIndex - 1;
this.name = (cell.Value != null ? cell.Value.ToString() : "");
this.tag = (cell.Tag != null ? cell.Tag.ToString() : "");
this.toolTip = cell.ToolTipText;
this.date = monday.AddDays(day);
this.classTime = cell.RowIndex;
// Get Homework
string selectedDay = this.date.ToString("d.MM.yy");
foreach (HomeWork hw in Data.homework)
{
if (hw.date.ToString("d.MM.yy") == selectedDay)
{
if (hw.time == this.classTime)
{
this.homework.Add(hw);
}
}
}
}
示例7: GetForeColor
private static Color GetForeColor(DataGridViewCell cell)
{
if (cell.Style.ForeColor != Color.Empty)
return cell.Style.ForeColor;
else
return cell.OwningRow.DataGridView.DefaultCellStyle.ForeColor;
}
示例8: Add
public virtual int Add(DataGridViewCell e)
{
var x = (__DataGridViewCell)(object)e;
InternalItems.Add(x);
return InternalItems.Count - 1;
}
示例9: ShowErrorMsgForCell
private void ShowErrorMsgForCell(DataGridViewCell cell)
{
ShowErrorMsg(cell.ErrorText);
_grid.Select();
foreach (DataGridViewCell c in _grid.SelectedCells)
c.Selected = false;
cell.Selected = true;
}
示例10: SetCellColor
private void SetCellColor(DataGridViewCell cell, Color fore, Color back)
{
cell.Style.BackColor = back;
cell.Style.SelectionBackColor = back;
cell.Style.ForeColor = fore;
cell.Style.SelectionForeColor = fore;
}
示例11: DataGridViewCellStateChangedEventArgs
/// <include file='doc\DataGridViewCellStateChangedEventArgs.uex' path='docs/doc[@for="DataGridViewCellStateChangedEventArgs.DataGridViewCellStateChangedEventArgs"]/*' />
public DataGridViewCellStateChangedEventArgs(DataGridViewCell dataGridViewCell, DataGridViewElementStates stateChanged)
{
if (dataGridViewCell == null)
{
throw new ArgumentNullException("dataGridViewCell");
}
this.dataGridViewCell = dataGridViewCell;
this.stateChanged = stateChanged;
}
示例12: add_grid_column
public void add_grid_column(string name, string header, DataGridViewCell cell_template, DataGridView dgrdview)
{
DataGridViewColumn dgrdview_col = new DataGridViewColumn();
dgrdview_col.Width = column_width;
dgrdview_col.Name = name;
dgrdview_col.HeaderText = header;
dgrdview_col.CellTemplate = cell_template;
dgrdview.Columns.Add(dgrdview_col);
}
示例13: Display
public void Display(ref DataGridViewCell cell)
{
Opened = true;
listBox1.DataSource = new BindingSource(Helper._elReader.Items, null);
listBox1.DisplayMember = "Key";
listBox1.SelectedValueChanged += listBox1_SelectedValueChanged;
_cell = cell;
this.Show();
}
示例14: ReceiptFilterInfoForm
public ReceiptFilterInfoForm(DataGridViewCell cell, DataTable dt, string fieldName, string SStorehouseId, int matType)
{
InitializeComponent();
this.dt = dt;
this.cell = cell;
this.fieldName = fieldName;
this.SStorehouseId = SStorehouseId;
this.matType = matType;
}
示例15: getCellValue
public static string getCellValue(DataGridViewCell cell, bool text = false)
{
string str = "";
str += cell.Value;
if (text)
{
str = "'" + str + "'";
}
return str;
}