Tag: datagridview

将.txt文件放入DataGridView

我有一个openFileButton ,当点击它时,将打开一个如下所示的文件: RefDeg Part# Xcntr Ycntr Rot PkgStyle U6 IC-00279G 33.411 191.494 0 QFP32 U1 IC-00272G 38.011 200.644 90 BGA177 U5 IC-00273G 46.311 179.494 0 QFP40 R54 EXCLUDES 36.411 173.694 0 0402_2 R71 EXCLUDES 38.236 186.994 0 0402_2 R39 EXCLUDES 38.861 188.544 90 0402_2 C23 CAP-00130G 37.911 178.854 90 0402_3 C88 CAP-00010G 52.036 179.019 0 […]

循环datagridview中的每一行

如何循环每行readed? 在我的代码中,由于产品ID相同,行不会绑定到下一行,因此datagridview不会移动到新行,它仍然在同一行并覆盖价格(对于某些产品,我有两个价格) 。 如何循环它以显示相同的productID但它有不同的价格。 EX:1汉堡包含2个价格的汉堡包:1美元和2美元,当我得到循环它的数据时,重新应该有2行相同的产品但价格不同。 这该怎么做? 下面是我的代码 productID = odr[“product_id”].ToString(); quantity = Double.Parse(odr[“quantity”].ToString()); //processing data… key = productID.ToString(); if (key != key_tmp) { //update index… i++; //updating variable(s)… key_tmp = key; } if (datagridviews.Rows[i].Cells[“qty”].Value != null) //already has value… { currJlh = Double.Parse(ddatagridviews.Rows[i].Cells[“qty”].Value.ToString()); } else //not yet has value… { currQty = 0; } currQty […]

如何使用BindingSource绑定DataGridView中的导航属性(二级属性)?

我使用了两个实体类将值绑定到DataGridView 。 一个是估计和公司。 估计值包含“Id,Estimate Number,Estimate Amount,CompanyId”等列 。 公司有“Id,Company Name,Address”等栏目 我创建了两个BindingSource例如EstimateBindingSource和CompanyBindingSource 。 CompanyBindingSource将DataSource作为EstimateBindingSource ,将DataMember作为Estimates EstimateBindingSource将DataSource作为Estimates实体类,并且没有定义DataMember 。 我已使用网格DataSource将EstimateBindingSource绑定到DataGridView 。 在这里,我需要在DataGridView中显示估计数,估计金额和公司名称 。我无法实现这一目标。 注意: 我没有做任何逻辑背后的代码来做这个..需要只使用设计来实现这一点。

如何在水平滚动时防止DataGridView闪烁?

我正在使用Windows表单C#。 如屏幕截图所示,我有一个Form,它有一个用户控件,一个tab控件和一个DataGridView(30行和17列)。 我从SQL Server读取数据以填充DataGrdiView。 问题: 当我水平滚动时, DataGridView闪烁很多。 然而,垂直滚动工作完美,没有闪烁。 我看过这里 , 这里 , 这里和这里,但没有一个与我的问题有关。 任何人都知道在水平滚动时阻止DataGridView闪烁的任何解决方案。

DataGridView更改单元格背景颜色

我有以下代码: private void dgvStatus_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) { foreach (DataGridViewRow row in dgvStatus.Rows) { row.Cells[color.Index].Style.BackColor = Color.FromArgb(((GesTest.dsEssais.FMstatusAnomalieRow)row.DataBoundItem).iColor); } } 我尝试从背景颜色列设置每个单元格的背景颜色。 这不起作用颜色永远不会改变。 知道为什么吗? 我一直在环顾四周,但没有找到任何有用的东西

DataGridView设置列单元格Combobox

我在Datagridview中有这样的表: Name Money ————- Hi 100 //here Combobox with member {10,30,80,100} to choose Ki 30 //here Combobox with member {10,30,80,100} to choose 我想从combobox中更改列“Money”值 我试过这个,但不知道进一步: DataTable dt = new DataTable(); dt.Columns.Add(“Name”, typeof(String)); dt.Columns.Add(“Money”, typeof(String)); dt.Rows.Add(new object[] { “Hi”, 100}); dt.Rows.Add(new object[] { “Ki”, 30}); DataGridViewComboBoxColumn column = new DataGridViewComboBoxColumn(); var list11 = new List() { “10”, […]

如何更改datagridview选定的行背景颜色?

如何在C#windows应用程序中更改datagridview选定的行背景颜色?

从.txt文件读取,然后将数据导出到DataGridView

我知道这是一个可笑的问题,但是上帝,我花了整整一天的时间用它敲打它,它就行不通! 这该死的老师甚至没有提到任何关于将任何数据导入DataGridView的事情! 我有一个C#Windows Forms作业:我必须从.txt (用户)文件中读取数据并将其粘贴到C#Microsoft Visual Studio 2012中的DataGridView表中users.txt文件中的数据类似于TAB分隔符: ————————————————- ID Name Surname Telephone VIP Age Balance ————————————————- 0001 John Killer 1-500-300 0 13 2272 0002 Name Surname 1-500-200 0 27 225 0003 Martin King 1-500-400 1 41 1070 忽略标签名称(ID,Name,Surname …),我只是为了清楚起见而编写它们,真实文件中只包含原始用户数据。 现在,我之前创建了一个类Users ,它包含以下字段: ID 名称 姓 电话 要人 买了物品 价钱 然后创建一个DataGridView( usersDataGridView )并从其中的类Users中导入字段。 好的,从算法上说这是一件容易的事,不是吗? 我的想法是执行以下操作:使用StreamReader读取文件内容,将每行保存为字符串,然后使用\t作为String.Split的分隔符将字符串拆分为多个部分。 但是,一旦我将这些行拆分了……好吧,我基本上不知道如何将它们导入到DataGridView中(我知道它应该是一个DataSource但是…… […]

使用对象列表填充datagridview

我有一个包含一系列事务对象的List。 我要做的是在加载表单时在Datagridview控件中显示这些事务对象,基本上Datagridview应该表示事务寄存器的某些内容,以显示列表中每个事务对象的数据。 我必须承认在使用Datagridviews方面缺乏经验,而我在理解我需要做什么方面遇到了一些困难。 我的问题是,如何获取列表中每个对象的详细信息以显示在Datagridview中? 这是我的代码。 首先是交易类: public class Transaction { // Class properties private decimal amount; private string type; private decimal balance; private string date; private string transNum; private string description; // Constructor to create transaction object with values set. public Transaction(decimal amount, string type, decimal currBal, string date, string num, string descrip) { this.amount […]

DataGridViewComboBoxColumn名称/值如何?

我认为这很简单,就像在Access中一样。 用户需要将数据表中一列的值设置为1或2。 我想呈现一个combobox,显示“ONE”,“TWO”并在场景后面设置1或2,就像我在Access-Forms中做过很多次一样。 另一方面,如果显示该表,则它不应显示1或2,而是显示ComboBox中的相应字符串。 我怎样才能让这个简单的任务工作?