How to Delete DataGridView Rows using RemoveAt? - vb.net

Im just new to vb.net and I need to delete some specific rows but
DataGridView.Rows(8).Visible = False
does not work I also tried using
DataGridView.Rows.RemoveAt(8)
It deletes the row BUT the problem is when I try to perform this function again there's an erro that says index out of bounds
Please help Im really out of ideas in the moment
Thanks

Try to remove the row at the source (datasource) of your grid not delete the datagridview row

you can try
DataGridView.Rows.RemoveAt(DataGridView.CurrentRow.Index)
this is for Current Row
And you Can Change Index to remove Last Index
DataGridView.Rows.RemoveAt(DataGridView.CurrentRow.Index - 1)
And you Can Change Index to remove Next Index
DataGridView.Rows.RemoveAt(DataGridView.CurrentRow.Index + 1)

Related

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

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)

get rid of blank rows at the end in DataGridView

I have a very strange issue with a DataGridView, whenever I try to put some data through queries I get one extra blank row at the end.
How do I remove it?
DataGridView1.AllowUserToAddRows = False
There is a row at the bottom for the user to manually add data. I think you might want to remove this
before fill the data in the Grid view
Write down the Gridview1.Rows.Clear
Then Fill the data.

Searching for specific data in datagridview

I have to work on a project that has a datagridview without a datasource. Also it's done in vb.net. I want to loop through each row on a specific column to find specific data and set my focus on that record.
For Each item As C1.Win.C1FlexGrid.Row In myDataGrid.Rows
' something like searchFor/contains
' (no idea, can't find the right way to search) for mySpecificData
Next
Help is appreciated, best regards
I assume that you are using component One FlexGrid, so I had a look at the documentation at the according site. Each row has an Item Property so this example might work
For Each row As C1.Win.C1FlexGrid.Row In myDataGrid.Rows
if row.Item("COLUMNNAME") = YOUR_VALUE then
' select range
C1.Win.C1FlexGrid.Select(row.Index, COLUMN_INDEX);
end if
Next
If you'd like to directly access a cell you may use Select method instead.

How to fetch the selected row in a bindingsource

How to fetch the selected row in a bindingsource.
I thought this was the solution:
DataRow row = ((DataRowView)bindingSource1.Current).Row;
But I still get the whole datagridview
If I stand on 'row' open the tree while I'm running my application I can select the Itemarray and see the selected data. but dont know how the change this line
DataRow row = ((DataRowView)bindingSource1.Current).Row;
Could somebody help me solve this problem ?
object row = ((DataRowView)bindingSource1.Current).Row[i];
i is the column index
Never mind, I solved it like this
object[] obj = ((DataRowView)bindingSource1.Current).Row.ItemArray;

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