DataGridView, BindingSource and sorting in vb.net - vb.net

I am emulating the functionality of an old app in VB.Net. I have a DataGridView on my form which is bound to a BindingSource. I have a button on the toolbar which lanuches a sort dialog. The sort dialog allows sorting by up to 3 columns.
So I'm building a string from the results of the dialog and setting the BindingSource.Sort property with it. But this doesn't update my DataGridView. Am I missing a step - do I need to tell something to refresh?

I just tried this with a simple test app, and it sorted without having to call any refresh. Can you post some code? Are you sure you're building up the Sort string correctly?

Do you have to call the DataGridView.DataBind() method?
I'm so used to ASP.NET that I forget the WinForms stuff.

What is the underlying object, and does it support sorting? You can check via the .SupportsSorting property (iirc). If it is a DataTable then you should be ok.
Have you tried applying the sort directly to the Grid?
You can try calling BindingSource.ResetBindings(false) after you update the sort property, just to be safe, but you shouldn't have to.

Related

vb.net datagridview and bindingsource

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.

how to place the imagekey to the right side of the listview

I am trying to add an imagekey to my items and it works fine except that the image
appears on the leftside of the listview in vb.net.
What I am trying to do is have it appear on the right side or in another column,
but I can't seem to do that.
can anyone help?
Thanks
Gibit
I assume you want to have an image in some other column when the listview is in Detail mode. You can't do that in the standard .NET listview control by default. I believe you would need to override a bunch of drawing-related events and possibly deal with some Win32 calls to have images show in subitems.
However, there is an open source custom listview control for .NET called ObjectListView that supports this feature. You could use that instead of the built-in one.

Deleting bound item from DataGridView

I have a List of an object, set to DataSource of a BindingSource, set to DataSource of a DataGridView. Then I added a DataGridViewButtonColumn which I want a click to remove that record from the collection. So I simply call collection.RemoveAt(e.rowIndex) from the DataGridView CellClick event. However this produces an IndexOutOfRange Exception; "1 does not have a value"..
So is happening here? I have maybe a vague idea, but would like to understand exactly which events are failing etc.. and what do i need to do to perform this action properly?
EDIT:
This seems not to happen if I use a BindingList.. But when using a List, I get this problem..
The reason you're seeing the error is because you're ultimately binding to a List. List doesn't include the notifications of changes that your DataGridView needs to receive to reflect the changes you make.
If you really want to work around this you could do the following: just before you make a changes to your List, set the BindingSource's DataSource property to Nothing. When you're done making changes reset your List to the DataSource.
This is a pretty ugly solution as you can imagine. What you'll want to do this bind to an object that implements IBindingList, either a custom collection you create or a BindingList.
Here's a reasonable starting point for investigating this further:
DataGridView Control Overview (Windows Forms)

Hide main form initially...Possible? (VB language)

Is there a way to start a Windows Forms in (VB language) application with the main window not visible? Then later on when an external event occurs, I want to display the form.
How can I accomplish this?
Thanks.
Hint: See the 'Visible' property.
Initially you just put:
Load SuperAmazingForm
..then when you want to display the form, simply call its Show method as normal.
Doing it this way allows you to interact with the form's objects without the user being aware of it.
It depends on if you are doing this in Excel/Word or Access. If you are using Excel/Word then the Load MyForm syntax works. However, Access uses it's own variation of the standard UserForm. To load a form hidden you can do:DoCmd.OpenForm "MyAccessForm", WindowMode:=acHidden.

How does the tooltip control enhance all controls on the form with a new property?

When answering another question I started to wonder how I could Add new properties to all controls in a form just like the ToolTip-control does.
For example I could use that to Add a "IsDirty"-flag to all textboxes just by adding the component to the form and it would handle this for every textbox.
When adding the tooltip-control to the form all controls magically gets a new property "Tooltip on tooltip1" that can be set both programatically and in design view.
I want to be able to do my own enhancer like that.
It's an Extender Provider.