vb.net datagridview and bindingsource - vb.net

Im in the process over converting some legacy VB6 code over, in particular a TDBGrid linked to an ADODC data control.
Everything is going ok, ive got my columns and bindignsource reading sweet as a nut and performing what its supposed to do, correctly - but im having a problem converting this type of method over.
In the vb6 app, while a user scrolls through the grid, the grid fetchstyle (similar to cellformatting) go looking at the equivalent row of data in the adodc.
In .net, I cant seem to get that functionality to be the same, unless I add that field from the database, into a column in the grid and make it invisible (which I dont really want to be doing if i can help it) then read the cell via cellformatting and then perform some action, such as changing the cellstyle backcolor to something.
Is it possible to refer to a row in the bindingsource that would be the same row in the grid that a user is at, without having that field from the bindingsource - in a DGV column?
or do i just have to put up with placing more columns in the DGV than I want and just live with it?
Thanks!

I think you want the BindingSource.Current
object.

Related

vb datagrid refresh after updating data in another form

I have a couple of forms, one without datagrid and one with datagrid. The one without datagrid is for adding values to the database, and that happens. When I come to the page with datagrid, the updated value does not show up. If I see the tableadapter and it has the new values but the datagrid doesn't. I have tried .refresh() which obviously just redraws and un-binded and re-binded the datasource too but that doesn't work either. Any help will be appreciated.
You should put your data into something that inherits INotifyPropertyChanged, or create some classes yourself that do this. Since this might be a little complex for you, you can simply refresh the data by clearing and applying the DataSource again.
MyGrid.DataSource = Nothing
MyGrid.DataSource = DT
You will need to replace the grid name and DataSource with your variables

Custom DataGridView Cells

I need to create a custom control based on a datagrid. My need is to show the events of the day (I know there are other third-party controls).
I should redesign the cells in the datagridview but I do not know where to start, obviously do not want the code I understand that it is not a simple thing, but I would like to see one of your left indication on what to focus on.
Below is an image of what I would get

Is there an event which fires before a user enters a row into the datagridview in .net 3.5

I am trying to create a wrapper to replace the sheridan datagrid actvex control with a datagridview.
The sheridan datagrid control supports an event which fires just before the user is going to add a row to the grid called BeforeInsert.
Does anyone know of an equivalent event in the datagridview control or or some other code I could write which produces the same effect?
I'm having a look at all the events here, I don't see one for Adding or Inserting a row, just Added. Although there's one for Deleting and Deleted strangely enough. I won't pretend to know why. To your question, how exactly will users be adding rows? You could try playing around with the "AllowUserToAddRowsChanged" event and change that property programatically when the user wants to add a row.

Use databinding controls to add records to a dataset

I imagine this is a terribly Noobish question, and I hate to ask, but I've been trying to solve this problem all day,
I need to add rows to a DataSet using databound controls in VB.net.
I've set up the data bindings themselves, they're bound the the correct controls, and the BindingSource uses the correct DataSet. The DataSet is filled from the DataAdapter correctly, and the binding source works, as the navigation controls all work fine.
Here's the noob part: How do I use the controls to add new data to the DataSet?
I've been grappling with this all day. I've tried Google, this board, other boards, MSDN, everything I could think of, and nowhere did I find a simple tutorial on how to do it. Either I'm as thick as two short planks, or it's not as simple as I assumed it would be.
Could anyone help me with this please? It's driving me mad.
I guess there must be some kind of end-edit involved which would enable me to insert, update and delete records in the DataSet (as you would use with DataGridViews)
You can't add new data to the DataSet directly, you can add rows to the DataTables that reside in your DataSet.
You should have a button "Add item" or something like that, and in the event handler add the row to the data table. Ensure that the user can edit your edited row with your bound control and add a button "Save" which would do a TableAdapter.Update() on changed DataTable.
If you use a DataGridView, setting the property AllowUserToAddRows = true would add an empty, "dirty" row in which user can type data to add new records to the DataTable.
This two should get you started:
Walkthrough: Saving Data to a Database (Single Table)
Editing Data in Datasets

Adding several datasource on same column in DataGridView

I'm working on VB .NET 2008.
Target: Bind dynamic datasource in a cell of a Windows.Forms.DataGridView depending on the selection in previous column. The grid must have 7 columns. If the selection on comboboxcolumn 2 or 4 is done, the datasource of comboboxcolumns 3 and 5 mus change using a query with previous selection as parameter.
In a first try to develop this functionality i've tried to use Telerik.WinControls.UI.RadGridView control. I've created a customized celltemplate with a combobox in order to have different datasource for each cell on the same column. All worked fine but seems to be some kind of bug in RadGridView, because when the combobox is presenting the list, after selection the list continued showing, doesn't dissapears as expected.
Ok, after several days of fight with RadGridView, I give up, and I tried to use same strategy but using Windows.Forms.DataGridView. I've created two classes one inherited from DataGridViewComboboxCell and other from ComboBoxColumn, in order to insert my own combbox or have the chance to have access directly to the combobox values. But the combobox showed is the default combobox not my own combobox.
Anyone knows how can I create a custom comboboxcell but using my own combo, and having access from outside to this combo?
Thanks in advance.
Regards.
You might be overwhelming the abilities of your controls. You can always break them out into parent/child or master/detail grids instead of keeping them combined into one.