Tag: datagridview

如何在C#中动态创建DataGridView?

如何在C#中动态创建DataGridView? 你能举个例子吗?

突出显示datagridview单元格中的部分文本

如何突出显示datagridview单元格中的部分文本? 我正在使用C#。 例如用户搜索书。 单元格包含书签。 我想在书签中突出显示“book”。 谢谢。 版。 这段代码好吗? Private Sub DataGridView1_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting If e.RowIndex >= 0 And e.ColumnIndex >= 0 Then e.Handled = True e.PaintBackground(e.CellBounds, True) Dim sw As String = GetSearchWord(e.ColumnIndex) If Not String.IsNullOrEmpty(sw) Then Dim val As String = DirectCast(e.FormattedValue, String) Dim sindx As Integer […]

如何对绑定到EF EntityCollection 的WinForms DataGridView进行排序

我正在尝试将WinForms DataGridView绑定到EntityFramework4对象的EntityCollection 。 麻烦的是,我无法弄清楚如何让它(自动)排序。 我所做的就是将BindingSource的DataSource属性设置为实体的集合。 MyBindingSource.DataSource = CurrentItem.InvoiceNotes; 我真的希望我可以添加一个简单的配置来使它工作; 我真的不想将我的EF Collection包装在一个新的BindingList容器中。

指数超出范围。 必须是非负数且小于集合参数名称的大小:index

我正在尝试将数据逐行添加到datagridview这里是我的代码,它说:“索引超出范围。必须是非负数且小于集合参数名称的大小:index”是什么这意味着 ? 在我的代码中有任何问题 String Sqlstr2 = “select ItemName from Item where ItemID = ‘” + tbItemID.Text + “‘”; db.DataRead(Sqlstr2); string ItemName = db.dr[“ItemName”].ToString(); DataGridView dataGridView1 = new DataGridView(); dataGridView1.Columns[0].Name = “ItemID”; dataGridView1.Columns[1].Name = “ItemName”; dataGridView1.Columns[2].Name = “Qty”; dataGridView1.Columns[3].Name = “UnitPrice”; dataGridView1.Columns[4].Name = “Amount”; string firstColum = tbItemID.Text; string secondColum = ItemName; string thirdColum = tbQuantity.Text; […]

在DataGridView列中格式化TimeSpan

我见过这些 问题,但都涉及CellStyle Format值中没有的方法。 我只想显示小时和分钟部分(16:05); 不是秒(16:05:13)。 我试图强制秒值为零,但仍然像16:05:00。 如果没有使用像提供字符串或DateTime(并且仅显示小时/分钟部分)的kludge,那么我可以通过任何方式获得格式化以完成我想要的操作。

如果网格较小,则调整DataGridView的列以填充可用空间,并在网格大于可用空间的情况下使用滚动

我想根据所需的空间调整DataGridView的所有列,以完全显示其所有数据。 如果所需空间小于可用空间我希望网格填充这个超出空间,但如果可用空间不足以正确显示我想要DataGridView的所有列自动创建滚动。 是否有捷径可寻?

将按钮添加到Winforms DataGridView

有没有办法在C#中的Winforms DataGridView单元格中添加控件(例如按钮)? (我的目标是在网格的不同单元格中放置各种控件……)

以编程方式定义DataGridView列类型

我需要一种可以在运行时定义列类型的方法。 这是我的代码: foreach (DataGridViewColumn column in this.dataGrid.Columns) { ??? //ie column.type = checkbox } 如何在此foreach循环中定义列类型?

使属性在DataGridView中可见但在PropertyGrid中不可见?

假设我有一个我希望在DataGridView中显示的属性,但是当PropertyGrid中显示相同的对象时却没有。 我知道我可以使用[Browsable(false)] ,但是它隐藏在两个视图中。 我也可以做一个gridView.Columns[“blah”].Visible = false; ,但这与我想要的相反,因为它隐藏在DataGridView中而不是隐藏在PropertyGrid中。 有没有办法反过来? (没有创建一个全新的DataTable只是为了保持相同的数据减去一个字段,而是将所有内容重新绑定到那个 – 这真的是一种做事的kludge方式。)或者,我可以使用一个向DataGridView添加列的解决方案在实际课程中没有出现。

无法在System.Int32和System.String上执行“Like”操作。 DataGridView搜索和过滤

我有一个表单,当我从ComboBox中选择一个列名,并在文本框中键入它时,它会过滤并在DataGridView中显示搜索的条件。 当我搜索“引用”时,它是一个int数据类型,也是标识和主键。 我收到错误消息: “无法在System.Int32和System.String上执行’Like’操作。” 我的代码是 DataTable dt; private void searchForm_Load(object sender, EventArgs e) { SqlCeConnection con = new SqlCeConnection(@”Data Source=|DataDirectory|\LWADataBase.sdf;”); SqlCeDataAdapter sda = new SqlCeDataAdapter(“select * from customersTBL”, con); dt = new DataTable(); sda.Fill(dt); dataGridView1.DataSource = dt; comboSearch.Items.Add(“[Reference]”); comboSearch.Items.Add(“[First Name]”); comboSearch.Items.Add(“[Surename]”); comboSearch.Items.Add(“[Address Line 1]”); comboSearch.Items.Add(“[Address Line 2]”); comboSearch.Items.Add(“[County]”); comboSearch.Items.Add(“[Post Code]”); comboSearch.Items.Add(“[Contact Number]”); comboSearch.Items.Add(“[Email Address]”); } […]