|
It seems I found a solution.
Instead of trying to relocate the actual item by setting LookUpBindingSource Position after having filtered it, if I reread the value of ItemID from MainBindingSource inside its CurrentChanged event and everything works fine.
This is the complete code
Private Sub MainBindingSource_CurrentChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MainBindingSource.CurrentChanged
Me.FilterComboBoxDataSource()
Me.ItemIDComboBox.DataBindings("SelectedValue").ReadValue()
End If
End Sub
Private FilterComboBoxDataSource()
Dim updateModes As Dictionary(Of BindingMemberInfo, DataSourceUpdateMode) =
New Dictionary(Of BindingMemberInfo, DataSourceUpdateMode)
For Each b As Binding In Me.ItemIDComboBox.DataBindings
updateModes.Add(b.BindingMemberInfo, b.DataSourceUpdateMode)
b.DataSourceUpdateMode = DataSourceUpdateMode.Never
Next
Me.LookUpBindingSource.Filter =
String.Format("Field1 = {0} And Field2 = {1} And Field3 = {2}",
Me.Field1CheckBox.Checked,
Me.Field2CheckBox.Checked,
Me.Field3CheckBox.Checked)
For Each b As Binding In Me.IDTipoComboBox.DataBindings
b.DataSourceUpdateMode = updateModes(b.BindingMemberInfo)
Next
updateModes = Nothing
End Sub
Hope it's useful.
Stefano
|
|
|
|
|
I have a dropdown List
whose ID = 2.1, 2.2, 2.3 .....
If I do Me.txtItemNumber.Text = ddlKeyResultsMeaures.SelectedValue.ToString()
it just read 2 not 2.1 or 2.2 etc
Could u please hepl me in this
|
|
|
|
|
Why are you calling ToString() on the SelectedValue [^], since it is already a string?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Me.txtItemNumber.Text = ddlKeyResultsMeaures.items(ddlKeyResultsMeaures.Selectedindex)
try this
|
|
|
|
|
Hello,
I saw this code of developer we have doing something at my company and he's using the word "shared" in front of routines everywhere. For example, he has a dll that he's referencing from a website and lots of routines in the dll are coded "shared". These routines aren't doing simple formatting or soemthing that, they are doing DB work, etc. Is there a concern in how many times a shared routine can be called currently? I personally do not like his design at all and i'm curious what everyone else's opinions are about the usage. Is using shared in this way a lazy thing or ?
Any opinions are appreciated (within this topic - ha ha).
Thanks
Nathan
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
|
|
|
|
|
For starters, Shared is over-used.
You can (and should) use Shared on methods that perform a state-less operation, e.g. mathematical functions Math.Abs and Math.Sin
You could have a Shared method that say increments a counter inside a database, provided the whole operation is contained in the method.
And you can create a class that is entirely Shared (all its data members and methods are Shared) provided it represents a unique object, something you are sure you never will need more than one instance of. Not too many real-life objects would fill that description though, most things aren't unique (although they may start of as a unique instance, e.g. your app may currently have access to only one database, however that might change in the future).
|
|
|
|
|
Thanks Luc,
So if he has a routine that accepts 1-n arguments that could be different per call and does a search and update from/to a database - not a good candidate for a shared routine - correct or? Is there a limit to how many current calls can be made to a shared routine?
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
There is no limit on the number of threads that can call a static method at the same time.
Actually, any limit that does come up would be imposed by the design and coding of the code calling these methods and the data passed in. But, in general, there is no limit but the ones you impose yourself.
|
|
|
|
|
Thanks Dave,
Do you object to a design that seems to be flooded with "shared" use?
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
Yeah, it sounds as though it's way over-used. Those methods sound like they should be moved to an instance of a data layer.
|
|
|
|
|
nlarson11 wrote: not a good candidate
depends. Does the code need state? Or is it all self-contained, i.e. execute and forget?
nlarson11 wrote: Is there a limit to how many current calls can be made to a shared routine?
No more than for a non-Shared method. Again, see Math.Sin()
|
|
|
|
|
self-contained. ok good to know.
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
A Shared (static) method does not interact with the class it's defined in. Anything in your class that doesn't touch instance-members can be made shared.
Sometimes a procedural programmer will have trouble thinking in OO, generating lots of static methods that take lot's of parameters.
The OO-way makes it's handy to have all the parameters and other variables embedded in an object, and interact with those, each "group" of procedures becoming objects;
shared Sub MySBSOpener(sbs as Object, HowMany as integer, ByRef TestCount as Integer)
shared Sub MySBSTester(sbs As Object, HowOften as integer, Verbose as Boolean)
shared Sub MySBSCloser(sbs as Object, Title as String, ByRef TestCount as Integer, Verbose as Boolean)
Class SBS
private _howMany as int
private _howOften as int
Public Sub New(HowMany as Integer, HowOften as Integer)
_howMany = HowMany
_howOften = HowOften
End Sub
public Sub MyOpener()
public Sub MyTester()
public Sub MyCloser(Title As String)
public property Verbose as Boolean
public readonly property TestCount
get
return _testCount
end get
end property
End Class
This has the advantage that you can populate a list with these things, something that's a bit harder to do if all methods are static.
Bastard Programmer from Hell
|
|
|
|
|
thanks Eddy
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
You're welcome
|
|
|
|
|
I have dymanuc drop down generated controls ( in some cases I can have as many as 5,3.... or none).
If I have 3 drop downs then first needs to be enable and after they select 1 second and so on. How would I do this witout post back?
Currently I am adding
AddHandler ddlGroupStudentTypes.SelectedIndexChanged, AddressOf ddlGroupStudentTypesValueChanged
|
|
|
|
|
If your dropdowns are truly dynamic, then you are going to have to make a request from the server to get the next dropdown's values. In the most technical sense, that is a post to the server. I assume that you mean that you don't want to do a page refreshing style of a postback. In other words, you want an ajax call to load the data for the next dropdown.
You have two general schools of thought you can go with:
1. UpdatePanel. This lets you run things through your server side events, and it disguises the postbacks so they don't make the page refresh. Pros are that it is simpler to implement. You basically can implement it as you would if you wanted the dropdowns to do a postback to load the next one. Then you wrap the dropdowns in an update panel, and set a few things and you are done. The update panel makes all those postbacks become ajax calls that don't refresh the page.
Cons are that it is far less efficient in terms of bandwidth and server resources, and it can lead to some difficult debugging if you aren't familiar with the .net life cycle. Update panels result in a massive amount of auto generated javascript and additional markup being rendered to the browser which is not really ideal. Also, update panels only work for web forms applications, and are not available for MVC. I assume from what I saw in your question that you are doing web forms.
2. Ajax calls to web methods. Pros are that this is clean and efficient. You save tons on bandwidth consumption which can be a big deal for slow connection users. You also take a much lighter load on the server resources, which is a big deal for higher traffic solutions. You also are in much better control of what is rendered to the browser. Cons are that you have to know javascript a lot better than you would with update panels, and you have to take care of a few specifics that update panels abstract or take care of for you.
I vastly prefer the 2nd option. If you go with the ajax option, then I can give you some additional pointers and things to look out for. I would suggest you use jquery and set up something like:
in javascript:
$("#myDropDown1Id").change(function(){
$.ajax({...//look at jquery.com for your specifics. You set your address, and send your parameters
success:function(data){
//receive the data from your server and populate dropdown2
},
error:function(data){
//notify the user in some way
});//end of .ajax
});//end of change function
Then you need to have a function exposed to be called as a web service. In web forms, you can have a method on your code behind and annotate the method as a WebMethod, or you can add a web service to the project and have methods exposed there. The json parameters you pass in javascript must match the case of your parameters on the server side exactly, which can be a gotcha. Order of the parameters is also important I believe.
If you do it via an ajax call then your web forms code behind won't have wired up change events for your dropdown. Rather you have web methods exposed that take a value and return data to the client.
The other thing to look out for on web forms is that if you are building dropdowns client side, the web forms security will get mad at you when you do finally submit. You will get an error that your values weren't registered for postback. It is webforms effort to prevent malicious javascript from injecting invalid options into the values a dropdown can send back.
To fix that you need to call a registerforpostback method associating every value you send back in your web service with that dropdown. That one can be a pain to work the nuances out.
So there is a lot involved, and I obviously didn't give you a full explanation on every aspect. I hope I gave enough that you can google for details and get it working. Good luck.
|
|
|
|
|
I am inheriting my own datagridview (say MyDataGridView) from the standard datagridview control. What I want is that certain properties of MyDataGridView should have a different default value than what its base have. For example,
AllowUserToAddRows, AllowUserToDeleteRows, AllowUserToResizeRows properties should have the default values of False; so that when I drag MyDataGridView into a form in the IDE, the default values shown in the properties grid should be False.
Later on, if I want to change them to True from the grid, they will be set accordingly. Is it possible somehow? Please note that I don't want to set the default value of any custom property in MyDataGridView but the properties mentioned
above that are derived from the base.
Thanks.
VS.Net, Framework 4.0, VB.Net, C#.Net, WinForms
|
|
|
|
|
Have a try of this
Public Class Class1
Inherits DataGridView
Private _AllowUserToAddRows As Boolean = False
Public Shadows Property allowUserToAddRows() As Boolean
Get
Return _AllowUserToAddRows
End Get
Set(ByVal value As Boolean)
If _AllowUserToAddRows <> value Then
_AllowUserToAddRows = value
MyBase.AllowUserToAddRows = value
End If
End Set
End Property
End Class
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
modified 12-Jan-12 10:58am.
|
|
|
|
|
I tried the following way as well as yours on the Visible property of an inherited label but yet it stays True in the properties grid when compiled and dragged in the IDE. I need to change it manually to take effect.
Imports System.ComponentModel
Public Class MyLabel
Inherits Label
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
<DefaultValue(False)> _
Public Shadows Property Visible As Boolean
Get
Return MyBase.Visible
End Get
Set(ByVal value As Boolean)
MyBase.Visible = value
End Set
End Property
End Class
Another point is, I tried both ways on the AutoSize property too, with the default value of False. In that case though, in the properties grid, it was showing False but actually the property remains True, as that's what I can see while executing. In order to set the value to False, I need to set it to True and then back to False again.
|
|
|
|
|
You just need to set the relevant properties in the constructor of you custom control like this:-
Public Class MyDataGridView
Inherits DataGridView
Public Sub New()
InitializeComponent()
AllowUserToAddRows = False
AllowUserToDeleteRows = False
End Sub
End Class
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Hello,
- I am using DirectShowLib to acquire video from laptop camera and it can work well.
- I am trying to adjust the brightness by using the software but it does not work.
- As I move the track bar (tbBrightness), I want to change the brightness but it does not change.
The codes are as below :
Imports DirectShowLib
Imports System.Runtime.InteropServices.ComTypes
Private Sub GetSettings()
Try
Dim capDevices As DsDevice() = Nothing
Dim CamDevice As DsDevice = Nothing
Dim CamFilter As IBaseFilter = Nothing
Dim CamControl As IAMCameraControl = Nothing
Dim graphBuilder As IFilterGraph2 = CType(New FilterGraph, IFilterGraph2)
Dim nMin As Long = 0
Dim nMax As Long = 0
Dim nStep As Long = 0
Dim nDefault As Long = 0
Dim nFlags As Long = 0
Dim hr As Int64 = 0
capDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice)
CamDevice = capDevices(0)
If (CamDevice.Name = String.Empty) Then
MsgBox("No video capture devices found!", MsgBoxStyle.OkOnly)
Exit Sub
End If
hr = graphBuilder.AddSourceFilterForMoniker(CamDevice.Mon, Nothing, CamDevice.Name, CamFilter)
CamControl = CType(CamFilter, IAMCameraControl)
hr = CamControl.GetRange(VideoProcAmpProperty.Brightness, nMin, nMax, nStep, nDefault, nFlags)
Me.tbBrightness.Minimum = nMin
Me.tbBrightness.Maximum = nMax
Me.tbBrightness.SmallChange = nStep
Me.tbBrightness.Value = nDefault
Catch ex As Exception
End Try
End Sub
Private Sub tbBrightness_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbBrightness.Scroll
Try
Dim capDevices As DsDevice() = Nothing
Dim CamDevice As DsDevice = Nothing
Dim CamFilter As IBaseFilter = Nothing
Dim CamControl As IAMCameraControl = Nothing
Dim graphBuilder As IFilterGraph2 = CType(New FilterGraph, IFilterGraph2)
Dim hr As Int64 = 0
Dim nVal As Int64 = tbBrightness.Value
capDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice)
CamDevice = capDevices(0)
hr = GraphBuilder.AddSourceFilterForMoniker(CamDevice.Mon, Nothing, CamDevice.Name, CamFilter)
CamControl = CType(CamFilter, IAMCameraControl)
hr = CamControl.Set(VideoProcAmpProperty.Brightness, nVal, CameraControlFlags.Auto)
Catch ex As Exception
End Try
End Sub
I appreciate your guidance on fixing this problem.
cheers,
Goutam
|
|
|
|
|
Hello,
I'm new to posting in the forum and I've been learning a lot by lurking here. I can write VB programs fine, but have not attempted using the IO ports until now. I come from the embedded field and I am an electrical engineer.
That said, I have read and tried several examples I found on the net regarding the serial ports, with no luck. I am posting the message bacause I'm stuck in something I believe shouldn't be this difficult (but this is Microsoft, so it may well be ) I have a circuit I built and programmed that sends 3 bytes (no text) to the PC and the PC needs to send 3 bytes back to the circuit.
Any good serial port tutorials out there written for VB2010? I don't want to ask anyone to write the code for me as I want to learn so I can do it myself. Many I found are general .NET with examples in C++ which I don't understand (I don't program in that language)sending text but not bytes. Others are older VB versions and don't work in 2010 (or again, more text strings.)
I'll appreciate any help or guidance in the subject. Thanks!
|
|
|
|
|
|
Thank you. I'll check it out.
|
|
|
|
|