datagridviewrow

Why am I crashing and getting the wrong day of the week?

余生长醉 提交于 2019-12-25 16:39:59
问题 My system clock is 9/16/2014 (Tuesday) But in code, I'm always jumping to Monday. DayOfWeek dow = new DateTime().DayOfWeek; int columnNumber = 0; columnNumber = columnNumber + 0; foreach ( DataGridViewRow row in dataGridView1.Rows ) { switch ( dow ) { case DayOfWeek.Monday: columnNumber = 4; if ( (bool) row.Cells[4].Value == true ) // crashing here with NullReferenceException { row.Cells["activeTodayDataGridViewCheckBoxColumn"].Value = true; } break; I have a DataGridView Columns 0—3 are Text

Faster Method to Making DataGridViewRow's non-Visible

瘦欲@ 提交于 2019-12-23 17:13:53
问题 I'm using the following code to set a bunch of DataGridViewRow elements to be invisible. The rule I am using is to check the associated datasource for a boolean flag. If the flag is true, the row will be displayed. If not, it will be invisible. The following code works; however, it does so by consuming quite a bit of time: CurrencyManager currencyManager = (CurrencyManager)BindingContext[dataGridView.DataSource]; currencyManager.SuspendBinding(); foreach (DataGridViewRow row in dataGridView

DataGridView Preserve Selected Index and Scroll Position after update and reload

£可爱£侵袭症+ 提交于 2019-12-18 09:03:22
问题 I have some problem, don't now how to preserve the scroll position in a DataGridView . I have over 1000+ rows and scrolling back to edited row is painful. How can I preserve the scroll position and scroll to the edited row after refreshing data? 回答1: Save the row index, do your refresh, then set the FirstDisplayedScrollingRowIndex property. int index = dataGridView1.CurrentRow.Index; /* * Your Refresh Code */ dataGridView1.FirstDisplayedScrollingRowIndex = index; 回答2: You can get the current

How to set Cell value of DataGridViewRow by column name?

六月ゝ 毕业季﹏ 提交于 2019-12-18 03:17:13
问题 In windows forms, I'm trying to fill a DataGridView manually by inserting DataGridViewRows to it, so my code looks like this: DataGridViewRow row = new DataGridViewRow(); row.CreateCells(dgvArticles); row.Cells[0].Value = product.Id; row.Cells[1].Value = product.Description; . . . dgvArticles.Rows.Add(row); However, I would like to add the Cell value by column name instead of doing it by the index, something like this: row.Cells["code"].Value = product.Id; row.Cells["description"].Value =

How to solve error `You have specified an invalid column ordinal`

拟墨画扇 提交于 2019-12-13 04:57:07
问题 I am getting the following error: You have specified an invalid column ordinal I already checked the column number in my database and I know it's right. Here's my code: using (MySqlCommand cmd = new MySqlCommand(query, con)) { cmd.Parameters.AddWithValue("@ID", txtboxID.Text); MySqlDataReader dr = cmd.ExecuteReader(); while(dr.Read()) { int size = dr.GetInt32(3); int quantity = dr.GetInt32(4); string variant = dr.GetString(2); DataGridViewRow row = dataGridView2.Rows .Cast<DataGridViewRow>()

Not getting all rows when iterating through DataGridView rows

流过昼夜 提交于 2019-12-11 23:16:53
问题 In a VB.NET WinForms application I have a DataGridView with a checkbox as a non-bound column in the first column. I need to add to a collection of rows each row that has its checkbox checked. I'm using the below code to iterate through the rows and find the ones with a checked checkbox: For Each row As DataGridViewRow In dgvEmployees.Rows Dim chkCell As DataGridViewCheckBoxCell = DirectCast(row.Cells(0), DataGridViewCheckBoxCell) If Convert.ToBoolean(chkCell.Value) = True Then Console

Using a dynamic list of Custom Object and can't dynamically change dataGrid's cells properties

我的梦境 提交于 2019-12-10 17:21:55
问题 I am new to posting on Stack. I have searched for quite some time to a problem similar to mine. I am trying to change the checkboxes in a WinForms DataGridView from not read-only to read-only based on the object's boolean value dynamically. It is showing in debug mode that the change has happened but once it fully runs through, the checkbox cells that are supposed to be read only are still allowing check and uncheck functionality. I have left the commented out section in to show that I have

C# - How to pass the data from dataGridView1 to another using a button click?

社会主义新天地 提交于 2019-12-08 02:23:35
问题 I have a dataGridView1 , dataGridView2 and a ButtonAdd in one Form. The user will: 1- select any one "Cell" or the "entire Row". 2-select multiple Rows Then: the data selected will be moved from dataGridView1 to dataGridView2 when the button clicked. that's all what i need to do. My try: I have tried this solution after many searches and it's almost done but there's a little problem I couldn't handle: Full Code: private const string strconneciton = @"YourConnectionString"; SqlConnection con =

C# - How to pass the data from dataGridView1 to another using a button click?

半世苍凉 提交于 2019-12-06 12:51:59
I have a dataGridView1 , dataGridView2 and a ButtonAdd in one Form. The user will: 1- select any one "Cell" or the "entire Row". 2-select multiple Rows Then: the data selected will be moved from dataGridView1 to dataGridView2 when the button clicked. that's all what i need to do. My try: I have tried this solution after many searches and it's almost done but there's a little problem I couldn't handle: Full Code: private const string strconneciton = @"YourConnectionString"; SqlConnection con = new SqlConnection(strconneciton); SqlCommand cmd = new SqlCommand(); DataTable dataTable; private void

How to drag and drop row within the same datagridview

断了今生、忘了曾经 提交于 2019-12-03 10:14:18
问题 In a Windows App (Visual Studio)(VB) how do you drag and drop a single row to another postition to allow for the user to re-order the row? I haven't found any worthy examples for this yet. 回答1: Here is a vb version from this C# answer: How could I Drag and Drop DataGridView Rows under each other? The form class variables: Private fromIndex As Integer Private dragIndex As Integer Private dragRect As Rectangle The drag events: Private Sub DataGridView1_DragDrop(ByVal sender As Object, _ ByVal e