Vb.net Move A Datagridview Row to the last row when being edited - vb.net

I haven't found exactly what i need in the forums. I don't want to move selection or scroll index, all what I need to is to change the entire row with a specific index to be the last line in my datagridview.
I need this to happen automatically when i edit this row.
P.S. Datagrid is Unbound
for example:
dgv.rows(index).index=dgv.row.getlastrow
However, the debugger return an error that index is read only.
Please help guys!

This worked for me:
Dim curr_row As DataGridViewRow = idgv.Rows(Index)
Dim curr_index As Integer=idgv.Rows.GetLastRow(DataGridViewElementStates.Visible)
idgv.Rows.Remove(curr_row)
idgv.Rows.Insert(curr_index, curr_row)

Related

Datagridview add row form behind don't increment CurrentRowIndex

I have found a bug on datagridview (vb.net), if I add a row from code, the value of DataGridView1.CurrentRow.Index is always 0.
If I add row manualy (with mouse) the value of DataGridView1.CurrentRow.Index is right.
I have a function that add some rows from code and I have implement DataGridView1_CellValueChanged and I check if the first cell in selected row is empty or not, but this check always first row.
I've found this bug in this link, https://developercommunity.visualstudio.com/t/datagridview-event-rowsadded-doesnt-show-the-corre/2270 and microsoft don't want to fix it.
I can use a simple variable boolean for fix this bug, but maybe someone can help me for resolve definitly this error?
Thanks
That's not a bug. Microsoft even stated as much in the report you linked to. "By design" means not a bug.
The CurrentRow is the row that contains the CurrentCell and that is the cell that contains the caret. When the user adds a row in the UI, it is assumed that they will want to edit that row, so the grid moves the caret to the first cell in that row. When you add a row in code, there's no specific expectation that the user is going to want to edit that row because it wasn't the user who added it, so the caret stays where it is.
If you want a newly added row to be the CurrentRow then you need to assign a cell in that row to the CurrentCell property of the grid, e.g.
Dim newRowIndex = myDataGridView.Rows.Add()
Dim newRow = myDataGridView.Rows(newRowIndex)
Dim firstNewCell = newRow.Cells(0)
myDataGridView.CurrentCell = firstNewCell
You would probably put code like that into a method and then call that method whenever you wanted to add a row.

How to create new format on the 2nd datagridview base on the 1st datagridview in vb.net

Please see the Screen Shots
Screen Shot
I want a new format then I will export on excel..
the data in Datagridview1 is the imported excel..
then I want a new format in the datagridview2 as shown in image..
I don't how can I do that..
Thank you in advance
This is the syntax.
For Each drow As DataGridViewRow In DataGridView1.Rows
DataGridView2.Rows.Add(drow.Cells(0).Value, drow.Cells(1).Value, drow.Cells(2).Value)
Next
DataGridView2.Rows.Add() is index based. Putting drow.Cells(0).Value at the beginning will add it at the first column and so on and so forth.
drow.Cells(index).Value, index here is the index of the item you are getting from the column of your DataGridView1. Pretty straightforward. No much explanation needed I guess.

figure out rowindex on a row I just inserted?

I've got a vb project I am updating and it has a datagridview, a panel, and buttons along the bottom. The buttons control CRUD operations. The panel shows numerical up/downs and textboxes to represent the selected row.
I use some logic to keep track of current selected row and current row index for timer updates in the background. Upon delete I reset focus on the first row. Upon loading I set focus on first row. On update I keep current row focus.
Upon a good insert I would like to set the focus to the row I just inserted. But I do not know a way to determine what the rowindex value is for this freshly inserted row. My datatable which the datagridview uses is sorted on two id columns so it's not like the new entry will just jump to the bottom.
Any ideas on how I can implement this?
If you don't want to deal with the RowAdded event as Jay Riggs suggested, if you add it using a row object, as opposed to just Rows.Add, you should be able to pull that off of the row object after it's inserted.
Dim dgr As New DataGridViewRow()
DataGridView1.Rows.Add(dgr)
Me.DataGridView1.Rows.IndexOf(dgr)
This should also work for insert as well.
Check out the DataGridView RowAdded event; its DataGridViewRowsAddedEventArgs parameter includes the RowIndex property which gives you what you need.
The event fires everytime a row is added, so you'll have to either wire the event up when you want to check for added rows, or ignore the event when you don't care when a row is added (such as when your grid fills with data).
If you manually add rows to the DataGridView, then you can just use the return value from the Add method. Examples:
Dim newRowIndex As Integer = myDataGridView.Rows.Add()
myDataGridView.Rows(newRowIndex).Selected = True
No need to call IndexOf. If the DataGridView is bound to a DataSource then Jay Riggs' solution of using the RowsAdded event is the way to go.

DataGridView inserting new row when filling column headers

DataGridView inserting an extra row every time I populate with data. The row appears even if I only fill the column headers. This is causing problems when I try to get values of each cell.
Is there a way to avoid this perhaps in properties?
Thanks in advance for any suggestions.
It isn't very clear what your exact issue is.
The only behaviour I can think of that matches what you are describing is the AllowUserToAddRows property of the DataGridView. This provides a row at the bottom of the grid populated with empty, editable controls.
If you set the property to false, do you get the behaviour that you want?
Another option is to ignore this row when doing any other processing - the new row will have the property of IsNewRow set to true:
if (!dataGridView1.Row[i].IsNewRow)
{
//This is not the new row
}
(Sorry about the C# above - my vb.Net is very rusty at the moment)

Multi Band Infragistics UltraGrid Row Select problem

I am bringing in data from SQL that is to be displayed in a multi band ultragrid. This works great. It does what it is supposed to in this regard; however, if I try to select a row other than the first one, in any band of the bands, it freezes the program.
When the grid is loaded, the first row seems to be active (text is bold), so I tried doing an update on the active row. This got rid of the active row, but didn't fix the problem.
Thank you in advance for any help!
Are you using BindingList<> as your data source? Try converting to List<>.If you have to use BindingList<> then set the SyncWithCurrencyManager property on ultragrid to false. This tells the grid not to synchronize the current row with the current position of the CurrencyManager