Tag: datagridview

在C#Winforms中的DataGridViewCell内绘制一个实心圆或矩形

我想在DataGridViewCell的中心绘制一个小圆圈。 矩形也可以做到这一点。 我假设我必须在CellPainting事件中这样做。 我试过这个: if (e.RowIndex >= 0 && e.ColumnIndex >= 0) { if (dgv_Cuotas.Columns[e.ColumnIndex].Name == “Seleccionar” && Convert.ToBoolean(dgv_Cuotas.Rows[e.RowIndex].Cells[“pagada”].Value) == true) { e.CellStyle.BackColor = Color.LightGray; ; e.PaintBackground(e.ClipBounds, true); e.Handled = true; } } 它绘制了整个单元格,我只想要一个小圆圈或矩形,如下图所示: 我怎样才能做到这一点? 使用DataGridViewImageCell不是一个选项,因为我有格式错误。 我只能将DataGridViewCheckBoxCell更改为DataGridViewTextboxCell。 编辑:我可以将其更改为DataGridViewImageCell !! 不知道之前发生了什么,但我仍然无法在那里加载图像。 我只得到一个带红叉的白色方块(无图像图标)。 这是我的代码: dgv_Cuotas.Rows[row.Index].Cells[“Seleccionar”] = new DataGridViewImageCell(); dgv_Cuotas.Rows[row.Index].Cells[“Seleccionar”].Value = Properties.Resources.punto_verde; dgv_Cuotas.Rows[row.Index].Cells[“Seleccionar”].Style.ForeColor = Color.White; dgv_Cuotas.Rows[row.Index].Cells[“Seleccionar”].Style.SelectionForeColor = Color.White;

为什么我看不到添加到DataGridView的DataGridViewRow?

我试图在DataGridView中显示行。 这是代码: foreach (Customers cust in custList) { string[] rowValues = { cust.Name, cust.PhoneNo }; DataGridViewRow row = new DataGridViewRow(); bool rowset = row.SetValues(rowValues); row.Tag = cust.CustomerId; dataGridView1.Rows.Add(row); } 在表单加载时,我已将dataGridView1初始化为: dataGridView1.ColumnCount = 2; dataGridView1.Columns[0].Name = “Name”; dataGridView1.Columns[1].Name = “Phone”; 执行此代码后,会发生四件值得注意的事情: 我可以在dataGridView1中看到一个新行。 里面没有文字。 执行row.SetValues方法后,rowset为false。 行标记值已正确设置。 为什么DataGridView不显示数据?

Datagridview图像列设置图像 – C#

我有一个带有图像列的DataGridView 。 在属性中,我试图设置图像。 我单击图像,选择项目资源文件,然后选择显示的图像之一。 但是,图像仍显示为DataGridView上的红色x? 谁知道为什么?

如何validation是否已检查DataGridViewCheckBoxCell

我已将数据表绑定到DataGridView ,此数据表有一个名为“Status”的列,其类型为Boolean 。 我可以通过代码将值设置为true或false 。 但是,我无法弄清楚如何检查是否已经检查了给定的行。 这是我试图使用的代码,并且编译它显示错误“指定的强制转换无效”。 任何帮助,将不胜感激。 if (rowIndex >= 0) { var cbxCell = (DataGridViewCheckBoxCell)dgvScan.Rows[rowIndex].Cells[“Status”]; if ((bool)cbxCell.Value) { // Do stuff } else { // Do other stuff } }

如何使用C#检查datagridview中的空单元格和空单元格

我试图检查datagridview单元格的空值和空值…但我不能正确… for (int i = 0; i < dataGridView1.Rows.Count; i++) { if ((String)dataGridView1.Rows[i].Cells[3].Value == String.Empty) { MessageBox.Show(" cell is empty"); return; } if ((String)dataGridView1.Rows[i].Cells[3].Value == "") { MessageBox.Show("cell in empty"); return ; } } 我甚至试过这个代码 if (String.IsNullOrEmpty(dataGridView1.Rows[i].Cells[3].Value)) { MessageBox.Show(“cell is empty”); return; } 谁能帮我这个…

如何隐藏C#DataGridView默认*行?

C#DataGridView控件有一个默认的空行最后一行,标有*。 我怎么能隐藏它?

如何检查DataGridView是否包含“x”列并且“x”列是否可见?

如何检查DataGridView包含“x”列并且“x”列是否可见? 我到目前为止所有的一切都在下面。 if (Dgv.Columns.Contains(“Address”) & …. 谢谢

至少有一个DataGridView控件的列没有单元格模板

我得到了那个例外。 System.InvalidOperationException was unhandled Message=At least one of the DataGridView control’s columns has no cell template. Source=System.Windows.Forms StackTrace: at System.Windows.Forms.DataGridView.CompleteCellsCollection(DataGridViewRow dataGridViewRow) at System.Windows.Forms.DataGridView.get_RowTemplateClone() at System.Windows.Forms.DataGridView.RefreshRows(Boolean scrollIntoView) at System.Windows.Forms.DataGridView.RefreshColumnsAndRows() at System.Windows.Forms.DataGridView.OnBindingContextChanged(EventArgs e) at System.Windows.Forms.Control.OnParentBindingContextChanged(EventArgs e) at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e) at System.Windows.Forms.Control.set_BindingContextInternal(BindingContext value) at System.Windows.Forms.ContainerControl.set_BindingContext(BindingContext value) at System.Windows.Forms.ContainerControl.get_BindingContext() at System.Windows.Forms.Control.get_BindingContextInternal() at System.Windows.Forms.Control.get_BindingContext() at System.Windows.Forms.DataGridView.DataGridViewDataConnection.SetDataConnection(Object dataSource, String dataMember) at […]

在datagridview中搜索C#winfom

我想在DataGridView一个搜索选项,即User在TextBox键入字符串或int,类似的记录应该突出显示DataGridView 。 我尝试使用KeyPress事件,但没有工作。 if (Char.IsLetter(e.KeyChar)) { for (int i = 0; i < (dgemployee.Rows.Count); i++) { if (dgemployee.Rows[i].Cells["Employee"].Value.ToString(). StartsWith(e.KeyChar.ToString(), true, CultureInfo.InvariantCulture)) { dgemployee.Rows[i].Cells[0].Selected = true; return; } } 实际上,我需要搜索整个DataGridView ,而不仅仅是一列和一行。 那么最好的解决方案呢

如何使用MYSQL在C#中的datagridview中插入,删除,选择,更新值

下面是使用datagridview将值插入mysql数据库的代码。 但是selectcommand正在工作。它没有发生,因为我收到错误声明“列’用户名’不能为空”。 如果我使用ms访问数据库,则不会弹出此错误。 谁可以帮我这个事。 有没有其他方法可以这样做。 private void button1_Click(object sender, EventArgs e) { //Even using functions we can easily update the datagridview //Select_function(); try { //The container which displays the details. dataGridView1.Visible = true; //The binding object which binds the datagridview with backend. BindingSource bs = new BindingSource(); //The datatable through which data is exported to […]