Tag: datagridview

C#我可以在数据网格中显示类似于视图的可扩展树吗?

我正在使用C#,并希望我的数据网格的某些部分可以像树一样可以在这里完成,这可以吗? 谢谢

使DataGridView可视化地反映其DataSource中的更改的正确方法

假设DataGridView将其DataSource属性设置为DataView实例。 DataGridView dgv; DataTable dt; // … dt gets populated. DataView dv = dt.DefaultView; dgv.DataSource = dv; // … dt gets modified // The DataGridView needs to update to show these changes visually // What goes here? 我知道你可以将dgv.DataSource设置为null ,然后再设置为dv 。 但这似乎很奇怪。 我相信还有其他几种方法。 但是,正确的官方方式是什么?

DataGridView更新

我在C#中使用2005 Windows窗体。 我只在这工作了一天,所以请放轻松。 我想要一个提交按钮,保存对DataGridView的更改。 我已经将数据输入DGV并且可以编辑,但是卡在了Update()上。 我创建了一个名为scDB的.xsd和一个名为-SSIS Configurations Staging的DataTable。 然后我添加了一个带参数的新查询。 这是我到目前为止的代码: //Declared at top of form class scDBTableAdapters.SSIS_Configurations_StagingTableAdapter myStagingTableAdapter = new scDBTableAdapters.SSIS_Configurations_StagingTableAdapter(); //After a form event stagingGrid.DataSource = myStagingTableAdapter.GetDataBy(filterName.Text.ToString()); //On Submit click: myStagingTableAdapter.Update(?What Goes Here?); 什么传递给Update方法? 我知道它需要一个dataTable,但我不知道如何引用GridView中的内容。 在大多数代码示例中,人们定义了DataTable – 但我没有。 我假设这是在我创建TableAdapter时在幕后完成的。 谢谢您的帮助。

Datagridview,仅显示唯一值为Duplicate Cell Values C#2005

我有一些问题要显示值,但每次重复datagridview中的值,我使用Microsoft Visual C#2005和框架2.0。 当我编程时,我发现在循环内部我需要检查重复值并计算它们,如果出现新值显示值并发送邮件,我确实通过smtp获取邮件代码,但我需要重复值要计算和消除只留下原始单元格并更新其余部分,这是可能的,这是连接到网格的代码和数据生成我需要认真帮助这个,因为我还没有找到正确的网络代码可以有效地完成这项工作。 try { e.Result = “”; //int count1 = 0; int val = 6000; DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn(“ComputerName”, typeof(String))); //0 dt.Columns.Add(new DataColumn(“IP”, typeof(String))); //1 dt.Columns.Add(new DataColumn(“MAC”, typeof(String))); //2 dt.Columns.Add(new DataColumn(“Descubierto”, typeof(String))); for (int a = 1; a <= val; a++) { counter.Text = Convert.ToString(a); if (txtWorkGroupName.Text == "") return; […]

关闭表单后,DataGridView记录消失

我有一个datagridview,它没有绑定到数据库中的表。 datagridview由下拉列表的内容和按钮单击上的文本框填充。 我想阻止每次关闭表单时删除记录。 有没有办法保存datagridview中的记录而无需创建数据库表? 以下是我的代码: private void btnInsert_Click(object sender, EventArgs e) { this.dgInsertedInfo.Rows.Add(ddlVendorID.Text, txtDate.Text); }

DataGridView DataBindingComplete事件的替代方案

如此处所述,只要数据源的内容发生更改,或者DataSource等属性发生更改,就会触发DataGridView的DataBindingComplete事件。 这导致该方法被多次调用。 我目前正在使用DataBindingComplete事件对我的表单进行一些可视化格式化。 例如,我将第一列(第0列)中的文本显示为行标题,然后隐藏该列(请参阅下面的代码)。 private void grdComponents_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) { foreach (DataGridViewRow row in grdComponents.Rows) { row.HeaderCell.Value = row.Cells[0].Value.ToString(); } grdComponents.Columns[0].Visible = false; // do more stuff… } 没有必要多次执行此代码,我希望将其放入可能发生的地方。 不幸的是,当我将片段添加到我的表单的Load方法的末尾时(在我设置DataGridView的DataSource之后),它也没有用,也没有在DataSourceChanged事件中工作。

如何将datagridview行添加到xml文件?

我是c#的初学者,我在Form创建了一个dataGridView1 ,我在其中添加了一些行和列( 不使用DataSet和Datatable )。 现在我需要将dataGridView1的数据发送到xml文件。 每当我点击该按钮时,xml文件都应该更新 。 我需要在不使用Datatable (或表)的情况下执行此操作。 我试过下面的代码( 不工作 ) OnButtonClick XmlTextWriter newXml = new XmlTextWriter(“d:/newXML.xml”, Encoding.UTF8); DataSet ds = new DataSet(dataGridView1.Rows.ToString()); /* May be I am missing something here */ ds.WriteXml(newXml); xml文件已成功创建,但在其中显示 。 如果我添加BindingSource bs = (BindingSource)dataGridView1.DataSource; 在DataSet之前,它显示错误“对象引用未设置为对象的实例”。 注意:如果xml文件不是他们的,那么它应该创建一个。 提前致谢。

c#如果行不为空,则更改颜色

我有一张桌子上有一些值。 如果行单元格“名称”不为空,则将背景颜色更改为紫色。 Name ID Customers Niky 1 yes // here change background to violet 2 no Donna 3 yes // here change background to violet Baka 4 no // here change background to violet 5 yes 6 no 我试过这段代码,但我不工作,不知道为什么: foreach (DataGridViewRow row1 in dataGridView1.Rows) { if (row1.Cells[0].Value != null) { row1.DefaultCellStyle.BackColor = Color.Violet; } }

DataGridView Masked TextBox列

我有一个包含2列的DataGridView,我想为它创建一些输入掩码。 所以我发现了一个inheritance了maskedtextbox控件的小类,并允许你在datagridview中使用它。 一切正常,面具按预期工作,没什么大不了的。 继图书馆: http : //www.codeproject.com/Articles/26005/DataGridViewColumn-Hosting-MaskedTextBox 我的问题是,一旦行包含我需要的所有数据,按Enter或tab不会创建新行,即使我有datagridview1.AllowUserToAddRows = true。 然后我发现问题出在我链接的库中,因为当我添加一个简单的数据网格文本框时,按Enter或tab会创建一个新行。 所以我添加了这个例程,当我在最后一行的最后一列时,希望创建一个新行: private void dgOre_CellEndEdit(object sender, DataGridViewCellEventArgs e) { if(e.RowIndex== dgOre.Rows.Count-1 && e.ColumnIndex== dgOre.Columns.Count – 1){ dgOre.Rows.Add(); } } 这个例程的问题在于它确实添加了一行,但它在最后一行之前创建了它,创建了一个空隙,好像我在启动其他事件之前创建了一行。 我应该在maskedtextbox库中更改某些内容,或使用其他事件,但我不知道如何编辑和编辑内容。 以下是编辑控件的源代码: public class DataGridViewMaskedTextEditingControl : MaskedTextBox, IDataGridViewEditingControl { #region Fields private DataGridView dataGridView; private bool valueChanged; private int rowIndex; #endregion #region Constructor public DataGridViewMaskedTextEditingControl() […]

如何在Button Click事件上从DataGridView填充TextBox

我想从DataGridView控件填充按钮单击事件的数据: 我的代码是这样的 for (int i = 0; i < dgv_EmpAttList.Columns.Count; i++) { txt_EnrollNo.Text = this.dgv_EmpAttList.CurrentRow.Cells[i].Value.ToString(); txt_FirstInTime.Text = this.dgv_EmpAttList.CurrentRow.Cells[i].Value.ToString(); txt_LastOutTime.Text = this.dgv_EmpAttList.CurrentRow.Cells[i].Value.ToString(); txt_TotalHours.Text = this.dgv_EmpAttList.CurrentRow.Cells[i].Value.ToString(); }