datagridview

关于DataGridView控件中的数据排序

▼魔方 西西 提交于 2020-01-08 21:33:43
Windows 窗体 DataGridView 控件中的列排序有三种模式,通过每一列的SortMode属性修改,改属性是DataGridViewColumnSortMode的枚举值之一。 DataGridViewColumnSortMode枚举:   1.Automatic:文本框的默认排序方式。除非将列表头用于选择,否则单击列表头会对相应的列进行排序。   2.NotSortable:非文本框的默认排序方式。可以以编程方式对此列进行排序;未为排序标志符号保留空间。   3.Programmatic:可以以编程方式对此列排序,而且为排序标志符号保留空间。 以编程方式进行排序:    可以通过调用 DataGridView 的 Sort 方法以编程方式对其排序。   Sort方法的Sort(DataGridViewColumn,ListSortDirection) 重载采用 DataGridViewColumn 和ListSortDirection 枚举值作为参数。当按列值可以有意义地排序(但不想将该列配置为用于自动排序)的列排序时,此重载很有用。当调用此重载并传入具有 DataGridViewColumnSortMode.Automatic的SortMode属性值的列时,会自动设置SortedColumn和SortOrder属性并在列标头中显示相应的排序标志符号。   注意

Unable To set row visible false of a datagridview

对着背影说爱祢 提交于 2020-01-08 17:16:52
问题 I have a DataGridView where I set DataSource : taskerEntities te = new taskerEntities(); var OMsMasterDescriptiveIndicators = te.MyTable.Select(x => new lccls {Id = x.Id, name = x.name }).ToList(); MyGrid.DataSource = OMsMasterDescriptiveIndicators; with my class lccls as public class lccls { public string Id { get; set; } public Nullable<decimal> name { get; set; } } At a certain event I want to make the current row invisible: MyGrid.Rows[5].Visible = false; But I am unable to do this.

Unable To set row visible false of a datagridview

五迷三道 提交于 2020-01-08 17:16:08
问题 I have a DataGridView where I set DataSource : taskerEntities te = new taskerEntities(); var OMsMasterDescriptiveIndicators = te.MyTable.Select(x => new lccls {Id = x.Id, name = x.name }).ToList(); MyGrid.DataSource = OMsMasterDescriptiveIndicators; with my class lccls as public class lccls { public string Id { get; set; } public Nullable<decimal> name { get; set; } } At a certain event I want to make the current row invisible: MyGrid.Rows[5].Visible = false; But I am unable to do this.

Can't figure out how to get a column to appear as a Combobox with static options

馋奶兔 提交于 2020-01-07 15:46:55
问题 private List<string> mylist = new List<string>(new string[] { "Visitor Seen", "Update Reason", "Ghost Sighted! HELP!" }); private void setupDataGridView() { dataGridView1.Columns.Add("ID", "Visitor ID"); dataGridView1.Columns.Add("VisitorName", "Visitor Name"); dataGridView1.Columns.Add("SignInTime", "Sign In Time"); dataGridView1.Columns.Add("Reason", "Reason For Visit"); DataGridViewComboBoxColumn comboCol = new DataGridViewComboBoxColumn(); comboCol.Name = "comboActionableItem"; comboCol

C# Populate GridView from database with update and delete function

↘锁芯ラ 提交于 2020-01-07 08:32:43
问题 I have been hunting for a way to populate a GridView from a sql local db with edit and delete functionality without creating duplicates. So far I have got as far as creating a SQL query, storing the results as a datatable and pumping that in to the GridView. I cannot seem to figure out how to go about managing edit and delete functionality and hoping someone here can help. Much appreciated. Here's how I am populating the GridView: //Load data in to parameters gridview using (SqlConnection con

How to multiply all the values of a column?

假如想象 提交于 2020-01-06 23:43:20
问题 I've a DataGridView like this layout: I would like to find a way to multiply all values of the column "Quota", in particular, I wrote a code like this: If MetroGrid1.Rows.Count > 0 Then If MetroGrid1.Columns.Contains("Quota") Then Dim CostTotal As Decimal = MetroGrid1.Rows.Cast(Of DataGridViewRow) _ .Select( Function(x) Return CDec(x.Cells("Quota").Value) End Function ).Sum Dim risultato = CostTotal * giocata The problem is that the only mode available is the sum and average, but there is no

I want to get export from datagridview to text file but I get error

一个人想着一个人 提交于 2020-01-06 20:02:20
问题 I want to get export from datagridview to text file but i get following error : An unhandled exception of type 'System.Security.SecurityException' occurred in mscorlib.dll Additional information: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. This is my code : const string path = @"d:\export.txt"; if (!File.Exists(path)) { File.Create(path); } TextWriter sw = new

C# DatagridView search/filter

白昼怎懂夜的黑 提交于 2020-01-06 20:01:47
问题 I am new to c#, I am trying to use filter the datagridview based on combobox value. Initially I loaded datagridview with all the desired values from database, now I want whenever user selects anything from combobox, the values in DataGridView should also change. One Solution which works for me is to request the database on each combobox value change and it works... code is attached for that DataRowView view = (DataRowView)comboBox2.SelectedItem; int year = (int) view.Row["Year"]; DataTable dt

C# Change datagridview cells by dragging on them

折月煮酒 提交于 2020-01-06 19:50:06
问题 My program outputs information froma DataTable I collect form sql data into a DataGridview and the last column in the DGV is a checkbox. I want to know if there's any quick way/event I could use so whenever a user clicks and drags to make a large selection (like in the image, clicking on the second cell and dragging down), all the selected cells change their status as if the user had clicked on each individual checkbox? The goal is to have a quick bulk-edit way to check large selections since

C# DataGridView data-bound error with Grid.Rows.Add method

旧时模样 提交于 2020-01-06 19:39:12
问题 i have a DataGridView on the Form. I select some data from database and load them to datatable and after that i make reference this datatable to grid's datasorurce as below. string sql = ""; sql = "SELECT id,name,surname,code FROM t_persons"; DataTable dt = new DataTable(); ... adapter.Fill(dt); grid.DataSource = dt; and after that i want to add new row to this grid with grid.Rows.Add() method. But every time it gives an error Rows cannot be programmatically added to the DataGridView's rows