datagridview

Derived DataGridView drawing problem. Shows black regions

纵然是瞬间 提交于 2020-01-02 06:15:12
问题 Late Edit I tagged this as a C# question as well as C++ because the problem presents itself in both languages, and solution if shown would most likely be in the C# (the majority of the market). I have been developing an application under .net 2.0 (C++ to be specific, but irrelevant). This application uses a custom derived datagridview. This datagridview will occasionally have sever artifacting issues regarding the region of the DGV that does not contain cells, as well as the scrollbar. During

Using LINQ to get DataGridView row index where first column has specific value

淺唱寂寞╮ 提交于 2020-01-02 03:39:07
问题 I'd like to get the index of a DataGridViewRow, where the value of its first column matches. My code so far: string SearchForThis = "test"; int index = from r in dgv.Rows where r.Cells[0].Value == SearchForThis select r.Index; The compiler error: Could not find an implementation of the query pattern for source type 'System.Windows.Forms.DataGridViewRowCollection'. 'Where' not found. Consider explicitly specifying the type of the range variable 'r'. 回答1: DataGridViewRowCollection doesn't

DataGridView - “Cell Selection Style” - Edit Cell

南笙酒味 提交于 2020-01-02 01:15:11
问题 I'm working on a WinForm client with a DataGridView control. I notice users have to click once to select the cell and again to edit it. What is the way to change this to a single click edit mode? I thought I had seen something like this before but can't remember the name. 回答1: Well I have noticed a problem with EditMode.EditOnEnter It biases a lot of DataGriView's default behavior, which is irritating. Among others, the edited cell stays in edited mode even when the EndEdit method is

Get current cell column index in DataGridView CurrentCellChanged Event

浪子不回头ぞ 提交于 2020-01-02 01:08:10
问题 I have the CurrentCellChanged event handler of a DataGridView and i want to be able to access the current selected cells column index from the event handler. I used to have the code in the CellClick handler which has DataGridViewCellEventArgs as a parameter so i was able to get the column index from the event args parameter but the CurrentCellChanged event has EventArgs as parameters which i believe is supposed to imply that theres no data for this event. Is there a way to access the new

Change the back color of the cell for DataGridViewComboBoxColumn

五迷三道 提交于 2020-01-01 17:27:09
问题 I created a DataGridView object with columns of type DataGridViewComboBoxColumn to allow the user to select values from a drop down list. I want to color the back of the combo box if the user selected "high" for example. However, it doesn't color the combo box but only the combo box values. The code is: dgvOverallRisk.Rows[0].Cells[1].Style.ForeColor = Color.Aqua; dgvOverallRisk.Rows[0].Cells[1].Style.BackColor = Color.Red; And it looks like this: 回答1: Coincidentally, I just answered a

What exactly mean by this Urikind.relative

别来无恙 提交于 2020-01-01 09:23:14
问题 What i am doing is i will have a datagridview when i select a row and click on show button i would like to display the image along with some information for that i written the following code public partial class WpfWindow : Window { private UCPersons _ucPersons; public WpfWindow() { InitializeComponent(); // Create WinForms Usercontrol and // add it to the WindowsFormsHost _ucPersons = new UCPersons(); winFormHost.Child = _ucPersons; List<Person> persons = CreateSamplePersons(); _ucPersons

What exactly mean by this Urikind.relative

拥有回忆 提交于 2020-01-01 09:23:10
问题 What i am doing is i will have a datagridview when i select a row and click on show button i would like to display the image along with some information for that i written the following code public partial class WpfWindow : Window { private UCPersons _ucPersons; public WpfWindow() { InitializeComponent(); // Create WinForms Usercontrol and // add it to the WindowsFormsHost _ucPersons = new UCPersons(); winFormHost.Child = _ucPersons; List<Person> persons = CreateSamplePersons(); _ucPersons

C# DataGridView Check if empty

烈酒焚心 提交于 2020-01-01 07:56:25
问题 I have a datagridview which gets filled with data returned from a linq query. If the query returns no results I want to display a messagebox. Is there a way of checking to see if the datagridview is empty? Regards 回答1: You can find out if it is empty by checking the number of rows in the DataGridView. If myDataGridView.Rows.Count == 0 then your DataGridView is empty. 回答2: The DGV.Rows.Count method of checking if DGV is empty does not work if the option AllowUserToAddRows is set to true. You

C# Winform (Entity Framework) - cast databound DataGridView or BindingSource to DataTable

风流意气都作罢 提交于 2020-01-01 07:05:07
问题 I am working with C# Winforms and Entity Framework, my project is modeled on this link: Databinding with WinForms My question is how can I convert a DataGridView or a BindingSource to a DataTable ? I tried this code: DataTable data = (DataTable)(DataGridView1.DataSource); but that failed with an error: Unable to cast object of type 'System.Windows.Forms.BindingSource' to type 'System.Data.DataTable'. Then I tried the this code instead: BindingSource bs = (BindingSource)DataGridView1

How to add print dialog to the printpreviewdialog?

只愿长相守 提交于 2020-01-01 05:42:09
问题 My boss wants me to create the window form that has printing function, but he wants to print the datagridview after preview. So now I encourage the problem, I cannot print multiple set of paper or choose the printer or make any changes when click the print button on printpreviewdialog .When I click the button, it will direct print the paper. So I wish to join the printpreviewdialog and printdialog . Why the printpreviewdialog and printdialog can only be used in different buttons? It's lack of