datagridview

How to set “Unavailable” word for null values in DataGridView

大城市里の小女人 提交于 2020-01-05 05:47:30
问题 I have an employees table in which first number is set as not null and second number that can be **null* so when I call the employees information to view their information in DataGridView the null values appear as empty cells but I want to show "Unavailable" word instead of the empty cell , so how can I do this? 回答1: You can use either of these options: Set NullValue property of DefaultCellStyle of the column. It sets the cell display value corresponding to a cell value of DBNull.Value or

Can I have an 'offscreen' control?

女生的网名这么多〃 提交于 2020-01-05 05:09:31
问题 I'm trying to create a DataGridView cell class which hosts a control (all the time, not just while editing). So far, my approach has been to add the control to the grid and try to synchronise its position with that of the cell. Would it be possible instead to keep the cell offscreen, route mouse and keyboard events to it, and paint it onto the cell? UPDATE: By 'offscreen', I don't mean that it should be added to another control such that it isn't displayed; I mean that it should never be

vb.net - check if there are duplicate data in Datagridview

元气小坏坏 提交于 2020-01-05 04:20:08
问题 How do I check if there are duplicate in datagridview? I have this code: For x As Integer = 0 To DataGridView1.Rows.Count - 1 For y As Integer = x + 1 To DataGridView1.Rows.Count - 1 If DataGridView1.Rows(x).Cells(0).Value.ToString = DataGridView1.Rows(y).Cells(0).Value.ToString Then MsgBox("Duplicate Data!") Exit Sub Else save_data() Me.Close() End If Next Next the code above is okay if the duplicate data is following each other like this: Column1 (cell 0) | Column2 (cell 1) ----------------

DataGridView.IsCurrentRowDirty() not set with editable DataGridViewComboBoxColumn

可紊 提交于 2020-01-04 14:31:12
问题 I have a DataGridView with a DataGridViewComboBoxColumn which is bound to a List<IBrand> . In this combo box column, I allow the user to either select an existing value or type in a new one. When a user selects an existing value, IsCurrentRowDirty() correctly returns true. When the user types in a value, the IsCurrentRowDirty() always returns false when it obviously should return true. I've tried calling DataGridView.CommitEdit() in the CurrentCellDirtyStateChanged event but that does not

Custom DataGridViewCheckBoxCell visual update doesn't work in edit mode

廉价感情. 提交于 2020-01-04 14:06:51
问题 I have the following DataGridViewCheckBoxCell . the problem is the visual update doesn't take place immediately in the edit mode, only when i quit it public class CustomDataGridViewCell : DataGridViewCheckBoxCell { protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle

C# DataGridView checkbox independant from row selection

瘦欲@ 提交于 2020-01-04 13:46:15
问题 thx in advance for the help... I have a datagridview (c# Winforms) with a column of checkboxes. When any of these are clicked, it automatically selects the row. (Although not th eother way around). How do I de-couple row selection from the checcking of the checkbox ? In other words, I want to enable multiple row selection, without effecting the corresponding checkboxes, and also click multiple checkboxes without "automatically selecting" the rows where the checkboxes are "checked" ? ~Ron 回答1:

import data from excel 2003 to dataTable

怎甘沉沦 提交于 2020-01-04 13:45:55
问题 I am importing excel worksheets to a datagridview using the following code: Private Sub Browsimportbtn_Click(sender As Object, e As EventArgs) Handles Browsimportbtn.Click Dim textpath As String Dim textpath1 As String Dim opf As New OpenFileDialog If opf.ShowDialog = 1 Then textpath = opf.FileName textpath1 = opf.SafeFileName textpath1 = textpath1.Remove(textpath1.Length -4,4) Dim cnexcell As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & textpath & "; Extended

How do I bind an Anonymous action as new event handler using reflection

自作多情 提交于 2020-01-04 13:38:02
问题 I am writing a number of unit tests for Windows Forms, and so far have been able to figure out how to set private controls' properties and invoke their methods, using Reflection. But I am stuck on how to associate an in-line lambda to attach itself to an event occurring on one of the controls, in this case the DataSourceChanged event of DataGridView. public static void ObserveGrid(this Form form, string controlName, Action action) { var controls = form.Controls.Find(controlName, true); if

How can I detect when the scroll bar reaches the end of a data grid view?

…衆ロ難τιáo~ 提交于 2020-01-04 13:28:24
问题 I would like to detect when the scroll bar reaches the end of a data grid view, so I can run a function when this happens. I was exploring the Scroll event, but without success. Thanks. 回答1: This should get you close... place this in your Scroll event and it will tell you when the last row is visible: int totalHeight = 0; foreach (DataGridViewRow row in dataGridView1.Rows) totalHeight += row.Height; if (totalHeight - dataGridView1.Height < dataGridView1.VerticalScrollingOffset) { //Last row

DataGridView KeyDown Event not working

柔情痞子 提交于 2020-01-04 11:43:24
问题 I have a DataGridView with a KeyDown event. void dataGridView1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.C && e.Modifiers == (Keys.Control | Keys.Shift)) { MessageBox.Show("ok"); // to test if working } } The message box prompts when I press the key combinations. But that is only when the datagridview is empty (no rows of data). The code doesn't work when the datagridview has rows already. Is there any wrong with the codes? 回答1: The KeyDown event handler doesn't fire when