|
vkstarry wrote: loaddata is used to fill my Grid, but everytime i call it, the bindingsource.position move to first.
That sounds logical, doesn't it? When you (re)load data, the grid cannot "assume" that you're loading the same table in there - so it cannot retain it's position.
vkstarry wrote: nah, if i delete row 3 then my position will stay at row 3.
Either don't reload the grid when you delete an item, or "remember" your index and set it manually;
DataGridView1.CurrentCell = DataGridView1.Rows(1).Cells(0)
Note; this works for the DataGridView that's being shipped with the .NET framework. The DevExpress grid[^] will probably use it's own version of positioning. They've got their own documentation and support-forum which I try to avoid
Bastard Programmer from Hell
|
|
|
|
|
I'm just starting to learn VB 2010 (old VB6 programmer trying to learn new stuff) and I'm having a problem with the DataGridView control.
I've created a datasource to my Access database. It connects to a table in the database. The "Fill,GetData()" tableadapter command produces the appropriate number of rows when I preview the data. However, when I show the form that contains the DGV control no rows are displayed. The form_load event is the default code created by Visual Studio, namely:
Private Sub frmSetAwards_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.JRTableAdapter.Fill(Me.YingexpoDataSet.JR)
end sub
Can anyone suggest what might be the problem?
Thanks
|
|
|
|
|
That is insufficient code to work on. Is it a TableAdapter or a DataAdapter? And where/when/how do you bind it to your DGV? There should be a statement such as myDGV.DataSource = myDataSomething
BTW: I don't use adapters, I tend to fill a DataTable using a DbCommand.Read() loop, than bind the table to the DGV with
myDGV.DataSource = myDataTable
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
Well, the properties of the DGV control shows the DataSource as "JRBindingSource". The JRBindingSource object has as it's DataSource "YingExpoDataSet" The YingexpoDataSet is the datase that I created through the Data Sources wizard.
??
|
|
|
|
|
I've never used the wizard, I tend to write my code myself, that way I know what is and isn't going on.
I do expect you need to keep things in their logical order: first get the data present, then establish the binding; if not, I expect an explicit action would be required (I know removing and re-installing the binding works when the data has changed).
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
As far as I remember you have to attach your DataSet to the DataGridView
dim ds as YingexpoDataset
myDataGridView.DataSource = ds.DefaultViewManager
If you want you can do that with the form designer (top right corner of the DataGridView).
Regards
Mick
|
|
|
|
|
SpareRoom (VBPmanan15)
Find a flatshare or flatmate fast! 1000s of rooms
for rent in flatshares across London, Manchester,
Birmingham, Bristol, Leeds, Edinburgh, Glasgow
and the rest. www.spareroom.co.uk
|
|
|
|
|
We usually "vote to remove" spam around here - I've changed tactics and will be adding each domain to the mvp-hosts and the adblocker-blacklist. The more spammers post here, the less visitors they'll receive.
Have a wonderfull day
Bastard Programmer from Hell
|
|
|
|
|
Hello everybody,
I have a child form which is supposed to show an exact duplicate of a part of the main form including its controls - here I'm in particular speaking about a ComboBox. What I'm trying to accomplish is that the user can either change a setting on the main form's ComboBox or on the child forms ComboBox to have both forms update the underlying list of a Datagridview as well as the ComboBox/Datagridview on the other form.
Is there any 'best practices' way of synchronizing controls on two forms? I would surely have to avoid firing events twice (e.g. combo updated by user would update the corresponding combo on the other form and fire again).
Thanks for advice,
Mick
|
|
|
|
|
AFAIK you can achieve that by using simple data binding:
- create a small class describing each item, with at least two properties (e.g. string Display , and int Value );
- store your items in a generic List;
- for both ComboBoxes set the DataSource to that list, and the DisplayMember and ValueMember to the names of the relevant properties. The DisplayMember is what will be shown, the ValueMember what will be returned as the SelectedValue.
With both ComboBoxes set up identically, they will act like one, i.e. fully synchronized; however each of them will fire its events. So you can deal with each of them as if the other didn't exist.
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
modified 11-Feb-12 8:57am.
|
|
|
|
|
Hi Luc,
sorry for my late response, I had to find the time to figure that out and still find myself stuck.
Following your advice I defined the class "AirportRange"
Public Class AirportRange
Private _display As String
Public Property Display() As String
Get
Return _display
End Get
Set(ByVal value As String)
_display = value
End Set
End Property
Private _value As Integer
Public Property Value() As Integer
Get
Return _value
End Get
Set(ByVal value As Integer)
_value = value
End Set
End Property
End Class Storing the class in a generic list didn't work (e.g. I didn't know how to), so I used the designer and set up the class as a Project DataSource - after which VS creates an "AirportRangesBindingSource" from it. This I used as DataSource for the new comboBoxes on my main and child forms, setting DataMember and ValueMember to the properties as you suggested.
A problem arose: The forms show, but I can't define items for them - which results in no possibility to select any values from the ComboBox. The items obviously have to be defined in the class istself? At least when I open the "items" property, I get an error message saying it wouldn't be possible to set items as a DataSource is defined...
Can you help me out of that?
Thanks for now,
Mick
|
|
|
|
|
You should keep things simple, especially when you don't understand them well.
And not knowing the basics of generic lists is not acceptable nowadays!
Here is a demo class to describe the combobox items:
Public Class Item
Private myValue As Integer
Private myName As String
Public Sub New(ByVal number As Integer, ByVal name As String)
myValue = number
myName = name
End Sub
Public ReadOnly Property Valu() As Integer
Get
Return myValue
End Get
End Property
Public ReadOnly Property Name() As String
Get
Return myName
End Get
End Property
End Class
and this could be part of a Form that holds a number of comboboxes, all showing the same list, and working fully synchronized:
Private Items As List(Of Item)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Items = New List(Of Item)
Items.Add(New Item(1, "one"))
Items.Add(New Item(2, "two"))
Items.Add(New Item(3, "three"))
For Each ctrl As Control In Me.Controls
If TypeOf (ctrl) Is ComboBox Then
Dim cmb As ComboBox = CType(ctrl, ComboBox)
cmb.DataSource = Items
cmb.DisplayMember = "Name"
cmb.ValueMember = "Valu"
End If
Next
End Sub
That is all there is to it. No magic, no wizards involved.
PS: when you attach a SelectedValueChanged handler to each ComboBox, you'll see they all fire, the one you actually changed fires first, then the others in arbitrary order.
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
Actually I had built this solution (a custom control in connection with a custom 'changed' event both forms shared) before and discarded it – thinking your suggestion would show a completely different approach – because ... this approach only solves a part of my problem, raising another one:
Having every control fire it's changed events I end up actualizing the underlying lists twice (which is time intensive)! I had first tried to avoid that by identyfying the clicked control (passing the sender to the FindForm function), but there' obviously no difference between the index change by a 'real user selection' and a remote index change triggered by the other control's changed-event. Could that effect be avoided?
Regards
Mick
|
|
|
|
|
you could use a global variable GlobalVal to hold the current value of your synchronized comboboxes.
in each SelectedValueChanged handler, compare the new value to GlobalVal; when different do everything that needs to be done and update GlobalVal, when equal do less (or even nothing at all).
Which basically means you would be using a cache with just one entry.
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
Wow - you seem to be online day and night And yes, that makes sense and keeps it simple, too I'm going to check that out.
Thank you in advance
Mick
|
|
|
|
|
Hi,
I would like to register an XLL while installing a project using MSI.
I am using a VB.NET installer class to do this:
Imports System.ComponentModel
Imports System.Configuration.Install
Imports System.ArgumentException
Imports Microsoft.Office.Interop
Public Class Installer1
Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
MyBase.Install(stateSaver)
Dim targetDir = Me.Context.Parameters.Item("targetdir")
targetDir = targetDir.Substring(0, targetDir.Length - 1)
MsgBox(targetDir)
Dim myScript = targetDir + "MySuperAddin.xll"
MsgBox(myScript)
Dim objAddin As Object
Dim objEXL As Excel.Application = DirectCast(CreateObject("Excel.Application"), Excel.Application)
objEXL.Workbooks.Add()
Try
objAddin = objEXL.AddIns.Add(myScript, True)
objAddin(myScript).Installed = True
Catch ex As Exception
MsgBox("cannot open addin. /n Error: " + ex.Message)
Err_Handler:
MsgBox(Err.Description, vbCritical, "Error: " & Err.Number)
End Try
objAddin = Nothing
objEXL.Quit()
objEXL = Nothing
End Sub
End Class
When I run this code as a VB script on my desktop I dont have any issue.
it is a very standard way to install an addin
please see the link
http://stackoverflow.com/questions/1130301/uninstalling-excel-add-in-using-vbscript[^]
However when I run it during the installation I get
Error: 438 Member not found. (Exception from HRESULTS: 0x80020003 (DISP_E_MEMBERNOTFOUND))
I tried to find a solution using the following links:
1) http://support.microsoft.com/kb/172108[^]
and
2) http://support.microsoft.com/kb/213489/[^]
but NO success. it is a clear problem with OLE Automation Object. I would really appreciate a suggestion. MANY THANKS!!
|
|
|
|
|
My Google foo is failing me.
|
|
|
|
|
IIRC a 64-bit version of the OleDb data provider doesn't exist.
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
Well, it does.[^]
And normally I would be happy about that, but at the moment it's a bit of a problem to solve.
|
|
|
|
|
I stand corrected.
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
Curious...why would you want to check?
You're code is going to use the ACE that matches your code bitness. The connection string wouldn't change at all AFAIK.
|
|
|
|
|
It seems that the ACE OleDb that's getting installed with Office is always 32 bits, no matter what your operating system is.
But if you install the Microsoft Access Database Engine 2010 Redistributable you'll have the choice of 32 or 64 bits.
So I want to check not just whether it's installed or not, but also the bitness.
And if it doesn't check I will fallback to Jet OleDb which is preinstalled with the same bitness as the OS.
Or am I missing something obvious here?
|
|
|
|
|
Well, you have no fall back. Why? Bcause you cannot mix 64 and 32-bit code in the same process. This problem is solved at installtime, not runtime.
If your app is compiled as x64 or AnyCPU (and running on a 64-bit O/S), you cannot use the 32-bit drivers. The reverse is also true. If compiled x86 or AnyCPU (and running on a 32-bit O/S), you can't use 64-bit drivers.
The best solution to the problem is to install the requisite software your app needs to run, as is. If your app is compiled x86 or AnyCPU (on a 32-bit machine), then chances are everything is already installed. If your app is compiled AnyCPU (on a 64-bit machine) or x64, then you have to install the Reidistributable engine.
|
|
|
|
|
In my opinion, user can install both x64 and x86 version of any COM/Activex component with the same GUID, but when a program runs in 64bit mode, you can check registry entries to ensure which version is installed. The real registry key for a x86 component in WOW64 could be found at HKEY_CLASSES_ROOT\Wow6432Node\CLSID node instead of HKEY_CLASSES_ROOT.
|
|
|
|
|
Does anyone have a LICENCED copy of vsFlexgrid 8 ActiveX surplus to their needs that they wish to sell?
I need to update 1 VB6 prog to run on Win7 but find ComponentOne price is prohibitive for a 1 off job
I understand that this is permitted by the Licence agreement.
Jim
|
|
|
|