Tag: 单元格

将矩形添加到pdfpcell itextsharp中

如何使用itextsharp将具有特定宽度,高度和背景颜色的矩形添加到PdfPCell中? 像这样的东西: PdfPCell cell = new PdfPCell(); Rectangle rectangle = new Rectangle(); rectangle.Width = 50f; rectangle.BackgroundColor = BaseColor.RED; cell.AddElement(cell);

数据绑定后如何将图像设置为数据网格视图?

我在数据绑定后向DGV单元添加图像时遇到问题。 这是我的代码: DataTable tab = conn.searchData(searchTmp); bindingSource1.DataSource = tab; DGV.AllowUserToAddRows = false; DGV.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader); //dont show this colls DGV.Columns[“zId”].Visible = false; DGV.Columns[“tId”].Visible = false; DGV.Columns[“tId2”].Visible = false; DataGridViewImageColumn co = new DataGridViewImageColumn(); System.Reflection.Assembly thisExe; thisExe = System.Reflection.Assembly.GetExecutingAssembly(); System.IO.Stream file = thisExe.GetManifestResourceStream(“MyApp.Resources.Tx1[k].gif”); System.IO.Stream file2 = thisExe.GetManifestResourceStream(“MyApp.Resources.Tx2[k].gif”); //和其他所有列 – 第一个灰色行 Bitmap bmp = new Bitmap(file); co.Image = bmp; […]

WPF Datagrid单元格,cellinfo和selectedcells +自定义选择

我想在WPF数据网格中操作选择,但是我对访问实际单元格并设置焦点并将它们标记为已选中存在问题。 任何人都可以解释一下:为什么没有一些简单的方法从** DatagridCellInfo **获取** DatagridCell **? 为什么几乎没有人在使用WPF数据网格? (我没看到很多Q / A投票) 有没有一种简单的方法如何为WPF数据网格创建自己的选择模式? 我的问题是什么 我想在不按Ctrl的情况下选择更多单元格(逐个)时在WPF Datagrid上进行自定义选择 。 我做得很好但是当我想取消选择一个选定的单元格时,我遇到了问题 – 只需单击它即可。 从列表中删除它不是问题。 问题在于,当它被点击时,它会成为焦点而且是高亮的,所有其他被选中的人都会关闭他们的暮色。 如果我选择另一个未选中的单元格,则所有选定的单元格将再次正确显示。 问题只出在取消选择中。 我的代码: XAML: 我已经在datagrid中填充了我制作的一些随机示例类对象的列表。 C#: private void DataGridCell_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { DataGridCell cell = sender as DataGridCell; DataGridCellInfo cellInfo = new DataGridCellInfo(cell); if ((cell.IsSelected)||(selectedList.Contains(cellInfo))||(selectedCellsList.Contains(cell))) { selectedList.Remove(cellInfo); selectedCellsList.Remove(cell); cell.IsSelected = false; mydatagrid.CurrentCell = selectedList[0]; […]

如何以编程方式将按钮添加到gridview并将其分配给特定的代码隐藏function?

在运行时我正在创建一个DataTable并使用嵌套的for循环来填充表。 此表我稍后将DataSource指定给gridview,并在RowDataBound上指定每个单元格的值。 我想知道如何给每个单元格一个按钮并将该按钮分配给代码隐藏function。 我将有12个按钮,每个按钮将包含不同的值。 如果它们都使用某种存储特定于单元格的值的事件调用相同的函数,我更愿意。 这是创建表的代码: protected void GridViewDice_RowDataBound(object sender, GridViewRowEventArgs e) { DataTable diceTable = _gm.GetDice(_gameId); for (int i = 0; i -1) { /*This is where I’d like to add the button*/ //e.Row.Cells[i].Controls.Add(new Button); //e.Row.Cells[i].Controls[0].Text = specific value from below //This is where the specific value gets input e.Row.Cells[i].Text = diceTable.Rows[e.Row.RowIndex][i].ToString(); } } […]

动态更改datagridview单元格颜色

我有一个填充了数据的dataGridView对象。 我想单击一个按钮,让它更改单元格背景的颜色。 这就是我现在拥有的 foreach(DataGridViewRow row in dataGridView1.Rows) { foreach(DataGridViewColumn col in dataGridView1.Columns) { //row.Cells[col.Index].Style.BackColor = Color.Green; //doesn’t work //col.Cells[row.Index].Style.BackColor = Color.Green; //doesn’t work dataGridView1[col.Index, row.Index].Style.BackColor = Color.Green; //doesn’t work } } 所有这三个都会导致表格以重叠的方式重新绘制,并且尝试重新调整表格的大小变得一团糟。 单击单元格时,值仍然突出显示,背景颜色不会更改。 问:如何在表存在后更改单个单元格的背景颜色?