Tag: datagridview

过滤DataGridView

我在网上搜索了我的问题的解决方案,我和我的studygrp正在制作一个datagridview,它从classLibrary获取信息。 一切正常但现在我们必须过滤它,但我能找到的只是绑定源,但这不是我的想法。 我只想要一个简单的filter,以便您可以在文本框中输入内容,如果它包含该信息,则会在datagridview上显示它。 我试过了: ((DataTable)dataGridView1.DataSource).DefaultView.RowFilter = “FromColumn like ‘%” + textBox1.Text + “%'”; 但它不起作用,我希望它能够…任何可以提供帮助的人?

派生DataGridView绘图问题。 显示黑色区域

Late Edit我将此标记为C#问题以及C ++,因为问题出现在两种语言中, 如果显示的解决方案很可能是在C#(市场的大部分)中。 我一直在.net 2.0下开发一个应用程序(C ++具体,但不相关)。 此应用程序使用自定义派生的datagridview。 此数据网格视图偶尔会出现关于不包含单元格的DGV区域以及滚动条的严重伪像问题。 在一些resize操作期间,黑色矩形将在datagridview的底部绘制,这实际上将限制网格的大小。 滚动条也缩小以适应非坚固区域。 在我看来,因为系统认为DGV尺寸错误,并且正在进入错误的区域。 alt text http://img12.imageshack.us/img12/2213/81356991.jpg 我只能通过两种方法来解决症状: 1.单击要resize的列将自动修复网格 2.在DGV中调用AutoResizeRows()函数将执行修复(但我相信是从第1点调用的)。 Custom DGV的一些修改: 1)配置为处理多行的拖放。 2)点1要求重写OnCellPainting以绘制拖动线。 如果看起来有症状,可以发布function。 3)问题总是发生在resize(手动和自动都会导致问题),但resize事件中没有自定义代码。 onCellPainting的后期编辑代码。 在gridview中重写的其他函数:OnMouseDown,OnCellMouseDown,OnClick,OnMouseMove,OnDragOver,OnDragDrop,OnDragLeave,OnKeyDown,其中任何一个似乎都没有症状 protected: [DebuggerStepThrough()] virtual System::Void OnCellPainting(DataGridViewCellPaintingEventArgs ^e) override { //draws red drag/drop target indicator lines if necessary if (this->AllowDrop && _DragDropCurrentIndex > -1 && ShowDragLines) { System::Drawing::Pen ^p = gcnew […]

DatagGridViewColumn.DataPropertyName到数组元素?

我正在使用DataGridView将其数据源绑定到List,并指定每列的属性。 一个例子是: DataGridViewTextBoxColumn colConcept = new DataGridViewTextBoxColumn(); DataGridViewCell cell4 = new DataGridViewTextBoxCell(); colConcept.CellTemplate = cell4; colConcept.Name = “concept”; colConcept.HeaderText = “Concept”; colConcept.DataPropertyName = “Concept”; colConcept.Width = 200; this.dataGridViewBills.Columns.Add(colConcept); {…分配其他列…} 最后 this.dataGridViewBills.DataSource=billslist; //billslist is List 显然,Class Bill有一个名为Concept的Property,以及每列的一个Property。 好吧,现在我的问题是,Bill应该有和Array / List / whateverdynamicsize包含称为Years的字符串容器。 让我们假设每个Bill都有相同的Years.Count,但这只在运行时才知道。因此,我不能指定像Bill.Years这样的属性来获取Bill.Years [0],Bill.SecondYear来获取Bills.Years [ 1] …等…并将其绑定到每一列。 我的想法是,现在我想要一个具有动态colums数量的网格(在运行时已知),每个列都填充了Bill.Years List中的字符串。 我可以在运行时根据Bill.Years.Count创建一个循环来向网格添加列,但是可以将它们绑定到Bill.Years List包含的每个字符串中??? 我不确定我是否足够清楚。 理想情况下,结果将是这样的,列表中的2个账单,以及每个账单的3年: ————————————–网格标题———- ——————— 名称概念年份1年份2年份3 […]

DataGridView单元格对齐将无法工作

我有一个我在C#Winforms项目中使用的DataGridView。 网格不会自动生成列。 我手动设置了列名和属性。 这包括单元格的DefaultCellStyle。 我希望所有类型为DataGridViewCheckBoxColumn的单元格都居中对齐。 我已在设计器中为此类型的每个列手动设置此对齐方式。 加载datagridview时,这些更改不会显示。 作为我的下一个方法,我在DataBindingComplete事件中使用了下面的代码(也没有任何效果) foreach (DataGridViewColumn dgvc in this.dgv_Automations.Columns) { if(dgvc.CellType == typeof(DataGridViewCheckBoxCell)) dgvc.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; } 调试时,上面的代码已经将对齐设置为中心。 但是,它仍然没有显示在网格上。 如果在DataBindingComplete事件期间我执行类似这样的操作,我可以使它工作: foreach (DataGridViewRow dgvr in this.dgv_Automations.Rows) { dgvr.Cells[“isErrors”].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; } 但是,我有很多这样的列,这样做真的没有意义。 编辑:我已经用这种方式实现了它,只有大约10行,因为在每个单元格上设置此属性存在非常明显的延迟。 我的问题是:这样做的正确方法是什么? 为什么设计师DefaultCellStyle不起作用?

填写dataGridView谢谢backGroundWorker

我有这段代码: private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { remplirDataGrid(); } private void frmChercherActesLoad(object sender, EventArgs e) { backgroundWorker1.RunWorkerAsync(); } private void remplirDataGrid() { dataGridView1.DataSource = ActeServices.getAllActes(0, 40); dataGridView1.Columns[0].Visible = false; dataGridView1.Columns[1].HeaderText = “Code acte”; dataGridView1.Columns[2].HeaderText = “Désignation”; dataGridView1.Columns[3].HeaderText = “Pris en charge”; dataGridView1.Columns[4].HeaderText = “Id article”; dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); } 这是方法getAllActe : public static IEnumerable getAllActes(int skipCount, […]

DataGridView – 同时输入和输出 – 这是DataGridView中的错误

我已经创建了一个C#Windows窗体应用程序,我试图尽可能简单地演示我遇到的问题。 我正在尝试使用DataGridView允许用户在一列中输入,同时从后台线程获取另一列中的更新。 问题是输入列实际上是不可编辑的,因为 – 我认为 – 用于输出列的更新会导致输入列在用户尝试更改时使用其当前值进行更新。 这是DataGridView中的错误吗? 有没有更好的方法来做这种事情? 谁能推荐一个好的解决方法? 以下代码演示了此问题。 “输出”列将不断更新,“输入”列几乎不可编辑。 我已将设计器代码(Form1.designer.cs)和Main(来自Program.cs)合并到表单代码(Form1.cs)中 – 因此以下代码应该自行运行。 using System; using System.ComponentModel; using System.Windows.Forms; using System.Timers; public partial class Form1 : Form { private System.ComponentModel.IContainer components = null; protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form […]

DataGridViewCombobox列中的AutoComplete有什么奇怪的行为?

我正在使用( EditingControlShowing )事件在DataGridViewComboBox列中启用自动完成。 private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { if (e.Control is DataGridViewComboBoxEditingControl) { ComboBox combo = (ComboBox)e.Control; ((ComboBox)e.Control).DropDownStyle = ComboBoxStyle.DropDown; ((ComboBox)e.Control).AutoCompleteSource = AutoCompleteSource.ListItems; ((ComboBox)e.Control).AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend; } } 但它有一个奇怪的行为,当我键入一些字符然后我离开单元格(Tab或右键),值没有改变。 但如果我重复一遍,价值就会改变。 从这里 ,您可以下载解释问题的源代码和(EXE)video。 你能帮助我让它正常工作吗?

如何在C#中取消CellEnter / CellLeave事件?

我有DataGridView 。 在一些单元格中,我添加了一些数据 如果我正在编辑的单元格是空的并且我即将离开它,则会向用户显示消息“bla-bla-bla”,并且处于编辑模式的单元格必须接收焦点。 为此,我使用CellEnter , CellLeave , CellEndEdit等,我想在检查单元格中输入的值后取消这些事件。 但我不是,它不起作用。 请帮我。 很高兴看到任何建议。 这是我的代码的变体。 我尝试过其他活动,但这很天真 。 private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { if (dataGridView1[e.ColumnIndex, e.RowIndex] == null) { MessageBox.Show(“Empty cell!”); dataGridView1.CurrentCell = dataGridView1[e.ColumnIndex, e.RowIndex]; } }

C# – DataGridView – 同一行上的图像和文本

我在DataGridView上寻找这样的东西: Image | Text | Text | Text | Image | Text 基本上,我只想在同一行上的图像单元格和文本单元格。 我能够让它与不同类型的工作,例如:复选框,文本等…但我无法使它与图像一起工作。 我收到此错误: Invalid Cast from ‘System.String’ to ‘System.Drawing.Image’ 有人知道解决方案或有关我应该怎么做的建议吗? 谢谢

以编程方式从DataTable创建DataGridview

我有以下代码: DataTable table = new DataTable(); //DataTable is filled with values here… DataGridView grid = new DataGridView(); foreach (DataColumn column in table.Columns) { grid.Columns.Add(column.ColumnName, column.ColumnName); } grid.DataSource = table; 当我检查grid , DataSource属性指示行数是正确的。 但是, grid.Rows计数为零。 相反,如果我在winform上创建DataGridView ,然后将其DataSource分配给DataTable ,则会自动添加DataGridView.Rows 。 我在这里缺少什么代码,以使DataGridView.Rows计数正确?