jjzjj

DataGridView

全部标签

C# 在更新或插入另一个窗体时刷新 DataGridView

我有2种形式,分别是formA和formB,formA允许用户插入和更新学生信息。formb只是一个DataGridView和按钮。当我在formA上插入学生,然后转到formB时,新学生没有显示在DataGridView上,如果我重新运行程序,新学生将出现在formB中。我尝试在表单b的按钮上使用它datagridview1.refresh();datagridview1.update();但还是不行。编辑:我的插入worker的代码cmd=newOleDbCommand("insertintoFWINFOS(ID,Name,Gender,DateOfBirth,Race,Worki

c# - 奇数/偶数 datagridview 行背景色

我有datagridview,现在我想根据行号是偶数还是奇数来更改每一行的背景颜色。我认为一定有更简单的方法可以达到这个目的。然后使用例如这部分代码并对其进行修改,以便更改dtg行的颜色。如果这段代码是实现此目的的方法之一,是否有人可以帮助我改进它,以便在rabge索引超出时它不会抛出异常?publicvoidbg_dtg(){try{for(inti=0;i感谢您的宝贵时间和答复。 最佳答案 表单设计器中有一个DataGridView备用行View样式选项。属性网格中的AlternatingRowsDefaultCellStyle

c# - 如何从datagridview的一列中读取数据

我想从datagridview的一列中读取数据。我的datagridview包含许多列,但我想读取所有单元格,但只能从一列中读取。我使用此代码阅读了所有专栏:foreach(DataGridViewColumncolindataGridView1.Columns)col.Name.ToString();但我想读取特定列中的所有单元格。 最佳答案 试试这个stringdata=string.Empty;intindexOfYourColumn=0;foreach(DataGridViewRowrowindataGridView1.Ro

c# - 如何手动将数据添加到 dataGridView?

我正在尝试运行这段代码,但出现异常:Indexwasoutofrange.Mustbenon-negativeandlessthanthesizeofthecollection.Parametername:indexprivatevoidLoadStudentGrades(intgradeParaleloId,intsubjectId){GradeStudentRepositorygradeStudentRepo=newGradeStudentRepository();students=gradeStudentRepo.FindAllGradeStudents().Where(g=>g

c# - 如何将按钮添加到 DataGridView 中的列

DataTabledt=newDataTable();dt.Columns.Add(newDataColumn("SoftwareTitle",typeof(string)));dt.Columns.Add(newDataColumn("Version",typeof(string)));dt.Columns.Add(newDataColumn("Uninstall",typeof(System.Windows.Forms.Button)));DataRowdr=dt.NewRow();dr[0]="App";dr[1]="1.0";Buttonuninstall=newButton(

c# - 将 DataGridView 的最后一行卡住为列的总和?

是否可以将DataGridView的最后一行作为列的总和,并且最后一行始终显示/卡住? 最佳答案 解决方案其实很简单,只需要你跳出框框思考一下。通常,一旦数据加载到您的GridView中,它的底部就会出现一个深灰色的行:您可以充分利用这个空间。您需要做的就是将几个标签拖到您的表单上,放置在您的GridView中,并应用背景颜色:在您的代码中,添加如下方法:voidUpdateTotal(LabelLabel,intNumber){//Calledfromanotherthread;facilitatesafecross-thread

c# - 由于 DataGridViewImageColumn,DataGridView 在默认错误对话框中抛出异常

我提出这个问题是因为在网上找到答案花了太长时间,这可能是一个常见问题-这是我第二次在我的应用程序中遇到它。当带有DataGridViewImageCell的新行变得可见,并且没有设置默认值时,我的DataGridView会抛出以下异常:TheFollowingExceptionoccurredintheDataGridView:System.ArgumentException:Parameterisnotvalid.atSystem.Drawing.Image.FromStream(Streamstream,BooleanuseEmbeddedColorManagement,Boole

c# - WinForms DataBinding 是否需要 BindingSource 和 BindingList?

我想显示DataGridView中的人员列表在Windows窗体应用程序中。我希望我的服务层返回一个Person对象列表(例如IList)。我希望列表中的更改反射(reflect)在DataGridView中反之亦然。我的理解是使用BindingSource有助于使用DataGridView.我的问题是双向数据绑定(bind)工作,我需要://pseudocodeBindingSource.DataSource=IBindingList或者我可以做:BindingSource.DataSource=IList有什么区别?如果我对列表进行更改,将DataGridView以任何方式更新?如

c# - 如何验证 DataGridViewCheckBoxCell 是否被选中

我已经将一个数据表绑定(bind)到一个DataGridView,这个数据表有一个名为“Status”的列,它是Boolean类型。我可以通过代码将值设置为true或false就好了。但是,我不知道如何检查给定的行是否已经被选中。这是我尝试使用的代码,编译它时显示错误“指定的转换无效”。如有任何帮助,我们将不胜感激。if(rowIndex>=0){varcbxCell=(DataGridViewCheckBoxCell)dgvScan.Rows[rowIndex].Cells["Status"];if((bool)cbxCell.Value){//Dostuff}else{//Doot

c# - 将 excel 数据粘贴到空白 DataGridView - 索引超出范围异常

我有一个包含以下内容的excel表:所以,我想要实现的是从Excel中复制它并将其粘贴到空白的DataGridViewView中。这是我目前的代码:privatevoidPasteClipboard(DataGridViewmyDataGridView){DataObjecto=(DataObject)Clipboard.GetDataObject();if(o.GetDataPresent(DataFormats.Text)){string[]pastedRows=Regex.Split(o.GetData(DataFormats.Text).ToString().TrimEnd("