datagridview

Double-click DataGridView row?

孤人 提交于 2020-01-29 04:36:24
问题 I am using vb.net and DataGridView on a winform. When a user double-clicks on a row I want to do something with this row. But how can I know whether user clicked on a row or just anywhere in the grid? If I use DataGridView.CurrentRow then if a row is selected and user clicked anywhere on the grid the current row will show the selected and not where the user clicked (which in this case would be not on a row and I would want to ignore it). 回答1: Try the CellMouseDoubleClick event... Private Sub

Winform中DataGridView绑定IList数据源后的排序

强颜欢笑 提交于 2020-01-26 23:09:01
首先,实现ICompare接口 ObjectPropertyCompare public class ObjectPropertyCompare < T > : IComparer < T > { private PropertyDescriptor property; private ListSortDirection direction; // 构造函数 public ObjectPropertyCompare(PropertyDescriptor property, ListSortDirection direction) { this .property = property; this .direction = direction; } // 实现IComparer中方法 public int Compare(T x, T y) { object xValue = x.GetType().GetProperty(property.Name).GetValue(x, null ); object yValue = y.GetType().GetProperty(property.Name).GetValue(y, null ); int returnValue; if (xValue is IComparable) { returnValue = ((IComparable

DataGridView InvalidOperationException reentrant call to SetCurrentCellAddressCore

走远了吗. 提交于 2020-01-26 03:35:28
问题 I've been working on this for about 8 months. It's been an annoyance more than anything until recently when I moved from a DataSet / DataTables to lists. Now the problem is a lot more prevalent (I think because the lists appear to be a LOT more efficient). This question has been asked a few times but none of them really hit on what truly is going on (nor are any of them answered). The odd thing is I can't isolate where in my code this is causing the exception as the debugger pulls up the

编辑datagridview单元格

那年仲夏 提交于 2020-01-26 02:08:35
以这3种为例,最简单的是第三种,直接让单元格处于可编辑状态,当完成编辑后触发CellEndEdit事件,最后对输入的数据进行处理。 1 private DateTimePicker dtp = new DateTimePicker(); 2 private ComBox sellstyle = new ComBox ();//设置全局变量 View Code 1 public PlanVindicateForm() 2 { 3 InitializeComponent(); 4 dgvReaschResult.Controls.Add(dtp);//在窗体的构造函数里将datetimepicker控件加入 5 this.dgvReaschResult.Controls.Add(this.sellstyle);//combox控件 6 this.sellstyle.Visible = false;//设置是否显示 7 this.dtp.Visible = false; 8 this.dtp.Format = DateTimePickerFormat.Custom;//设置显示格式 9 this.dtp.CustomFormat = "HH:mm"; 10 this.dtp.KeyDown += new KeyEventHandler(dtp_KeyDown);//注册控件用到的事件

C# DataGridView中指定的单元格不能编辑

喜欢而已 提交于 2020-01-26 02:07:15
ReadOnly属性的使用 DataGridView内所有的单元格不能编辑 当DataGridView.ReadOnly属性设定为True时, DataGridView内所有的单元格不能编辑。 但是使用这种方法可以对行进行删除。而且最下面的一行被表示,但不能输入。 [c-sharp] view plain copy print ? // DataGridView1的单元格只读 DataGridView1.ReadOnly = true; 只有被指定的列、行、单元格不能编辑 只有被指定的列、行、单元格不能编辑时,通过设定DataGridViewColumn、DataGridViewRow、DataGridViewCell对象的ReadOnly属性为True即可实现。 [c-sharp] view plain copy print ? //DataGridView1的第二列只读 DataGridView1.Columns[1].ReadOnly = true; //DataGridView1的第三行只读 DataGridView1.Rows[2].ReadOnly = true; //DataGridView1的(0, 0)的单元格只读 DataGridView1[0, 0].ReadOnly = true; DataGridView的ReadOnly设定为True时

Winform中DataGridView绑定IList数据源后的排序

牧云@^-^@ 提交于 2020-01-26 01:43:06
首先,实现ICompare接口 public class ObjectPropertyCompare<T> : IComparer<T> { private PropertyDescriptor property; private ListSortDirection direction; // 构造函数 public ObjectPropertyCompare(PropertyDescriptor property, ListSortDirection direction) { this.property = property; this.direction = direction; } // 实现IComparer中方法 public int Compare(T x, T y) { object xValue = x.GetType().GetProperty(property.Name).GetValue(x, null); object yValue = y.GetType().GetProperty(property.Name).GetValue(y, null); int returnValue; if (xValue is IComparable) { returnValue = ((IComparable)xValue).CompareTo(yValue); }

DataGridView not updating when bound BindingList is changed

我是研究僧i 提交于 2020-01-25 22:19:40
问题 Problem: I have a C# DataGridView (Windows Forms). I've set its DataSource to a custom SortableBindingList I've found online. When I add/remove items to/from the bound list, the DataGridView doesn't update until I reset the DataSource. HOWEVER, if I don't use this custom SortableBindingList and use the standard BindingList, then it works just as expected. But I need to be able to sort. I am using EntityFramework, if that's of any help. I've tried: Making my entities inherit

DataGridView not updating when bound BindingList is changed

蓝咒 提交于 2020-01-25 22:19:25
问题 Problem: I have a C# DataGridView (Windows Forms). I've set its DataSource to a custom SortableBindingList I've found online. When I add/remove items to/from the bound list, the DataGridView doesn't update until I reset the DataSource. HOWEVER, if I don't use this custom SortableBindingList and use the standard BindingList, then it works just as expected. But I need to be able to sort. I am using EntityFramework, if that's of any help. I've tried: Making my entities inherit

Object reference not set to an instance of an object when changing DataGridView colors

泄露秘密 提交于 2020-01-25 21:06:09
问题 I need to change the colors of a data grid view rows according to the data in the rows. My code is: foreach (DataGridViewRow Myrow in datagrid1.Rows) { if (Myrow.Cells[0].Value.Equals("Red")) { Myrow.DefaultCellStyle.BackColor = Color.Red; } { Myrow.DefaultCellStyle.BackColor = Color.Green; } } But when I try to run it I get: Object reference not set to an instance of an object I assume it's because it keeps looping every row until it reaches some which has a null value. How do I stop it from

How to set value of a DataGridView Cell programatically?

末鹿安然 提交于 2020-01-25 11:36:05
问题 I am trying to clear the cell if certain conditions are met. But its not working. UPDATE Private Sub DataGridView1_CellLeave(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellLeave Dim laspac As Int16 = DataGridView1.Columns("LASPAC").Index If e.ColumnIndex = laspac And DataGridView1.Rows(e.RowIndex).Cells("CType").Value.ToString.Trim() = "B" Then Dim B_LASPAC As DataGridViewCell = DataGridView1.Rows(e.RowIndex).Cells("LASPAC")