datagridview

How can I natural string sort a datagridview that is databound to a datatable

老子叫甜甜 提交于 2021-02-11 06:10:05
问题 In my program, I have a datagridview that is bound to a datatable using a binding source. What I would like to accomplish to be able to sort the datagridview by a column using a natural string sort. Sample Column Data: XAB-1 XAB-2 XAB-11 XAB-3 XAB-1A XAB-10 XAB-1B Desired Result: XAB-1 XAB-1A XAB-1B XAB-2 XAB-3 XAB-10 XAB-11 I have tried using the datagridview.sort method passing in a natural string Icomparer, but the sort function cannot be used when the datagridview is databound. I have

How can I natural string sort a datagridview that is databound to a datatable

亡梦爱人 提交于 2021-02-11 06:09:55
问题 In my program, I have a datagridview that is bound to a datatable using a binding source. What I would like to accomplish to be able to sort the datagridview by a column using a natural string sort. Sample Column Data: XAB-1 XAB-2 XAB-11 XAB-3 XAB-1A XAB-10 XAB-1B Desired Result: XAB-1 XAB-1A XAB-1B XAB-2 XAB-3 XAB-10 XAB-11 I have tried using the datagridview.sort method passing in a natural string Icomparer, but the sort function cannot be used when the datagridview is databound. I have

Add new blank row to datagridview c#

时间秒杀一切 提交于 2021-02-10 23:40:16
问题 I have a DataGridView that has a DataTable as the DataSource . Now I want to insert a new empty row to the DataGridView and make it totally black (like a divider line). I have tried to copy one line and make it black with this: Datagridview1.rows.insertcopies(2,2,1); But I'm getting this error: rows cannot be programmatically added to the datagridview's rows collection when the control is data-bound. How can I keep the DataGridView the way she is and just insert a blank row? Clarification : I

Add new blank row to datagridview c#

ⅰ亾dé卋堺 提交于 2021-02-10 23:36:10
问题 I have a DataGridView that has a DataTable as the DataSource . Now I want to insert a new empty row to the DataGridView and make it totally black (like a divider line). I have tried to copy one line and make it black with this: Datagridview1.rows.insertcopies(2,2,1); But I'm getting this error: rows cannot be programmatically added to the datagridview's rows collection when the control is data-bound. How can I keep the DataGridView the way she is and just insert a blank row? Clarification : I

Delete selected row from DataGridView and MS-Access Database

人盡茶涼 提交于 2021-02-10 15:04:55
问题 I am trying to delete the selected row from DataGridView and MS-Access database.. Private Sub ButtonEditDelete_Click(sender As Object, e As EventArgs) Handles ButtonEditDelete.Click If Not Connection.State = ConnectionState.Open Then Connection.Close() End If Try If Me.DataGridViewEdit.Rows.Count > 0 Then If Me.DataGridViewEdit.SelectedRows.Count > 0 Then Dim intStdID As Integer = Me.DataGridViewEdit.SelectedRows(0).Cells("Username").Value Connection.ConnectionString = "Provider=Microsoft.ACE

How can I use a List<Dynamic> as with DataGridView.DataSource? [closed]

白昼怎懂夜的黑 提交于 2021-02-08 12:05:59
问题 Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . Improve this question I'm trying to bind a List<dynamic> to a DataGridView DataSource property. While there are no errors when compiling there are no columns being displayed either. If I pre-create the column I get the rows to display, but there's no data in them. Simply put, how can I properly use a

How to get DataGridViewRow from CellFormatting event?

不问归期 提交于 2021-02-08 10:41:29
问题 I have a DataGridView and handle event CellFormatting. It has a parameter called: DataGridViewCellFormattingEventArgs e With e.RowIndex in it. When i do: DataGridView.Rows[e.RowIndex] I get proper row from collection. But when I click at a header of a column to sort it by other column than default one and user DataGridView.Rows[e.RowIndex] I get unproper row. It is because Rows collection do not reflect order of rows in DataGridView. So how to get propert DataGridViewRow from RowIndex in

Index was out of range after deleting multiple rows from the datagridview? C#

自古美人都是妖i 提交于 2021-02-08 10:13:08
问题 I use an ArrayList for my binary search. The datagridview's rows is added to the ArryList. When I deleting a single row from the datagridview, it works almost perfectly. The problem is when I delete many rows from the datagridview from the top or the bottom and middle, it gives me an error. How can I refresh or update the ArrayList after I deleted a row from the ArrayList (datagridview)? The error: 'Index was out of range. Must be non-negative and less than the size of the collection.

How to sum Time from a DataGridView Columns

一个人想着一个人 提交于 2021-02-08 08:59:22
问题 I have a DataGrid with a time column that I need to sum to get the total time, but I can't get that! I'm using this code to try the time sum, with Linq: foreach (DataGridViewRow row in dataGridView1.Rows) { textBox8.Text = dataGridView1.Rows.Cast<DataGridViewRow>() .AsEnumerable() .Sum(x => decimal.Parse(x.Cells["Duracao"].Value.ToString())) .ToString(); } Can anybody help me here? Regards 回答1: Have a look at below code sample. May be it will help you : private void BindGrid() { // Bind Grid

C# DataGridView BackColor Not Overwritten

左心房为你撑大大i 提交于 2021-02-08 08:25:23
问题 I have DataGridView on my form application. After retrieving data from a table in the database and displaying them in DataGridView , I apply a green color to some cell's BackColor of the rows if a certain condition is met. After those cells are colored green , the program makes them go through another condition, which colors the whole row's BackColor red if they fail to satisfy the condition. However, it seems like pre-colored cells cannot be overwritten with a new color. Even if I apply the