|
Hey I have found a way to do exactly what i want to achieve; the only problem is . . . the required values are only added once the row has 'lost focus' and not when selected from the combobox
here is the code
(Again a collection of dummy string values have been added to the combobox for ease)
Public Class Form1
Private Sub DataGridView1_RowValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles DataGridView1.RowValidating
Dim row As DataGridViewRow = DataGridView1.Rows(e.RowIndex)
If Not row.Cells("Column1").Value Is Nothing Then
If row.Cells("Column1").Value.ToString = "Prod 01" Then
Dim coid As String = "Product Description 01"
row.Cells("Column2").Value = coid
row.Cells("Column3").Value = "1.00"
row.Cells("Column4").Value = "10.00"
e.Cancel = False
End If
If row.Cells("Column1").Value.ToString = "Prod 02" Then
Dim coid As String = "Product Description 02"
row.Cells("Column2").Value = coid
row.Cells("Column3").Value = "1.00"
row.Cells("Column4").Value = "11.00"
e.Cancel = False
End If
End If
End Sub
End Class
Any ideas on how to implement this using the code you posted earlier? . . I have tried many times but unable to figure out how to string it all together.
The above code works perfectly (as far as i can tell at present anyway) other than the fact, it generates the values once focus has been lost from the row and NOT when the user selects it from a value in the combobox.
It's taken me most of the day through countless hours of web searching and trialing to get this far, hopefully we can get this problem sorted and perhaps an article may have to be written to help other users (im sure i'm not the only one wanting to achieve this) because there is nothing that I have found on the net addressing this issue.
anyways thanks for your help so far, . .i trust we will put this issue to bed soon (i can almost taste it)
Many Thanks
|
|
|
|
|
Thank you for your code, this is starting to give me an insight as to what I need to do.
Here is what I have done, however I am unable to get this to work I am VERY new at this and dont quite know what event to fire
Dim HookedCombo As ComboBox
Public Sub OnComboIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim strItemCode As String = Trim(HookedCombo.Text) 'Value Of ComboBox
'#NOTES#-----------------------------------------------------------------------
'I have populated the combobox with some dummy string values
'Item 01, Item 02, Item 03 etc....
'In my final atempt I will just read this off a database but I first
'need to understand how to get this to work without complicating it with
'a database.
'
'The next line does not work I keep geting the error;
'
'Index was out of range. Must be non-negative and less than the size of the collection.
'Parameter name: index
'
'I have noted that when the DataGridView loads (blank) the row count is 1
'using that I tried to deduct the row count (i) by 1 (i-1) however i still get the same
'problem.
If strItemCode = "Item 01" Then
Dim i As Integer = DataGridView1.SelectedRows(0).Index
DataGridView1.Rows(i).Cells(1).Value = "Item Description 01"
End If
End Sub
Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
If DataGridView1.CurrentCell.ColumnIndex = 0 Then
HookedCombo = TryCast(e.Control, ComboBox)
If HookedCombo Is Nothing Then
Return
End If
AddHandler HookedCombo.SelectedIndexChanged, AddressOf OnComboIndexChanged
End If
End Sub
Any ideas?
|
|
|
|
|
Hi, just got to my computer, I've been doing Banking, Shopping - you know - boring stuff like that.
Two things that you can try, while I am looking into this, and your other post.
First: This is just a general point. Whenever an event handler is used to handle a given event for more than one control you should use the sender parameter to determine which of the controls you are dealing with. In this particular case it doesn't matter but it is a good habit to get into.
So:
Public Sub OnComboIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim TheCombo As ComboBox = CType(sender, ComboBox)
Dim strItemCode As String = Trim(TheCombo.Text) 'Value Of ComboBox
' This means that you always get the "Text" of the ComboBox that caused this event
' As I said above, in this particular case that is the same thing as HookedCombo, but that won't always be true
is preferred to:
Public Sub OnComboIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim strItemCode As String = Trim(HookedCombo.Text) 'Value Of ComboBox
Second:
Try changing:
If strItemCode = "Item 01" Then
Dim i As Integer = DataGridView1.SelectedRows(0).Index
DataGridView1.Rows(i).Cells(1).Value = "Item Description 01"
End If
to:
If strItemCode = "Item 01" Then
DataGridView1.CurrentRow.Cells(1).Value = "Item Description 01"
'The point is, and probably the reason you are getting the error, although you are 'using' a particular row
' it may not be selected and therefore won't appear in the SelectedRows collection. However CurrentRow
' always points at the row with the cursor in.
End If
I'll have a look at your other post now, and I'll wait a bit before replying, assuming I have something to say of course , just in case the above works. Perhaps you'll let me know?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hey thanks!! Will make the above changes today and let you know my progress, I have a massive (non-computer orientated) day today so may not get the chance until later on tonight. But will keep you informed.
Thanks Again
|
|
|
|
|
Hey thanks for your help, I am still trying to work this issue out have been flat out lately and not at my computer alot so progress is becoming very slow, . . however i will keep you posted on my progress. Have you managed to find a way?
|
|
|
|
|
The following works as I think you described your requirements.
Public Class DGVComboIndexChangedForm
Private productListMember As List(Of String) = New List(Of String)
Dim HookedCombo As ComboBox
Private Sub DGVComboIndexChangedForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
productListMember.Add("Product 1")
productListMember.Add("Product 2")
productListMember.Add("Product 3")
CType(Me.dgvItems.Columns("ItemID"), DataGridViewComboBoxColumn).DataSource = Me.ProductList()
End Sub
Private Sub OnEditControlShowing(ByVal sender As Object, ByVal e As DataGridViewEditingControlShowingEventArgs) Handles dgvItems.EditingControlShowing
If dgvItems.CurrentCell.ColumnIndex = 0 Then 'use the index for your comboboxcolumn
HookedCombo = TryCast(e.Control, ComboBox)
If HookedCombo Is Nothing Then
Return
End If
AddHandler HookedCombo.SelectedIndexChanged, AddressOf OnComboIndexChanged
End If
End Sub
Public Property ProductList()
Get
Return Me.productListMember
End Get
Set(ByVal value)
Me.productListMember = value
End Set
End Property
Private Sub OnComboIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim TheCombo As ComboBox = CType(sender, ComboBox)
Dim strItemCode As String = Trim(TheCombo.Text) 'Value Of ComboBox
Select Case (strItemCode)
Case "Product 1"
dgvItems.CurrentRow.Cells("ItemStock").Value = "1"
dgvItems.CurrentRow.Cells("ItemPrice").Value = 1.1
Case "Product 2"
dgvItems.CurrentRow.Cells("ItemStock").Value = "2"
dgvItems.CurrentRow.Cells("ItemPrice").Value = 2.2
Case "Product 3"
dgvItems.CurrentRow.Cells("ItemStock").Value = "3"
dgvItems.CurrentRow.Cells("ItemPrice").Value = 3.3
End Select
End Sub
End Class
It is essentially as per the mods I suggested in my last post.
The class above is a Form with a DataGridView called dgvItems .
I manually added three columns to the grid using the Add Columns option from the Smart Tag on the DataGridView
1) DataGridViewComboBoxColumn named ItemID
2) DataGridViewTextBoxColumn named ItemStock
3) DataGridViewTextBoxColumn named ItemPrice
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi,
I'm a french network admin and I need some help to implement the code on this page:
Implementing a Read-Only 'File Open' or 'File Save' Common Dialog[^]
I work in a internet café and a lot of my young users uses this dialog box to navigate in the system file and destroy all my security settings.
This article is exactly what I'm searching for several mouth ago but... I'm not a developer!
Can someone explain to me how to implement this code by a step by step guide? It will be very great. And is there a way to reverse it if I need?
Sorry for my poor langage and my "noob" post but I really need some help.
Thanks for your answers.
Best regards,
Greg.
modified on Sunday, July 26, 2009 9:39 AM
|
|
|
|
|
Hi Greg. I am guessing this is a security problem rather than a programming one. If patrons of your internet café have the security access to modify your system files, that's what you need to address. Just make sure your "important files" are set to be accessible only by administrators, then make sure the accounts your patrons are using have significantly less privileges.
|
|
|
|
|
Hi Mike,
First thanks for your answer but I really need to implement this code. I try to explain to you my problem.
I have 16 computers running Xp Home and no domain, I 'm using a Cybercafé program named "Cyberlux" who need the administrative rights to run, and all my computers have 20 games installed on it. I have modified a lot of registry keys to ameliore the settings security and I have hide all the disk and importants documents on it but some of my young users find the way to access to all the system file with this f****** dialog boxes.
The hack : They go on a Web page where you can upload an image for exemple with a "browse" button on it, the dialog box open, they just have to put the entire path of a file on the field "Name of the file" to acceed where they want (hidden files or not). They go to the folder of my cybercafé program and move or delete the security files.
I hope you understand my problem and can explain to me how to apply this code.
Thanks for your answers.
|
|
|
|
|
You can't use this code to replace the File Dialogs in other applications. You REALLY need to overhaul your networks security so that your users do not have permissions to do anything that they are not supposed to do.
|
|
|
|
|
Okay,
Thanks for your reply I try to found another way to block the access to my important system files.
Best regards,
Greg.
|
|
|
|
|
Yeah, it's a matter of setting proper NTFS permissions on your folders.
|
|
|
|
|
It's not so easy, look at my answer to Mike Ellison, I explain exactly my problem.
Perhaps you know a registry key I can modify to completly disable this dialog box?
Thanks.
|
|
|
|
|
Yeah, I read that, and my answer does not change.
The base of the problem is that you're running an app that needs admin permissions. Either find another app, or learn how Windows security works. You can create an admin equivilent ID that has no permissions to various parts of the file system.
There is no way to disable those dialog boxes.
|
|
|
|
|
Hi there. Yes, just to add my voice to what Dave has already posted - he's right. You'll definitely need to handle this through NTFS file permissions.
Given the nature of your cafe though, have you considered running your 20 machines in a genuine Windows domain? It wouldn't cost much to set up a server, let it be your primary domain controller, and have the 20 clients authenticate against it. You could then manage the security for all from one location. Just something to think about.
|
|
|
|
|
Hi, that's right, I don't remenber that I can activate the security tab on xp home edition. Now it will be easy to manage my rights. And a 2003 server is too expansive for my society but it will be the best effectively.
Thanks to have spend time to answer at my stupid question, I apologize.
Best regards,
Greg.
|
|
|
|
|
For what it's worth, I didn't think it was stupid.
|
|
|
|
|
I'm looking for links (if possible) to good looking application UI's written using Windows Forms. I am wanting to see how good a program UI built using Win Forms can look, but with free stuff only, of course. Thanks
modified on Sunday, July 26, 2009 4:24 PM
|
|
|
|
|
Hi ,
i want to make dialer in vb.net,so if anybody able to help me i will be thankful to him/her.i need to know what are ther reqirement for dialer.If any code or article is there than plz provide me.
Thanks
|
|
|
|
|
hi
iam currently using vs.net 2005 to make a window form on c#
i notice the event dragdrop for the listview control and would like to know if it is possible to drag a row from a listview to another row in the same listview and triggering an event as i was hoping to use it the group the 2 rows together
|
|
|
|
|
Is this[^] the type of thing you're looking for?
For what it's worth, I found it by searching for "listview drag and drop" in Google.
|
|
|
|
|
This is what I have currently:
(1) My form
(2) My menu bar with all the clicks I want on it
(3) A text box docked at the bottom of the form
This is what I'd like to happen:
(1) On launch of the program -
(i) I'd like for the program to ask a question, such as "What is your name?"
(2) On the answer of that question based upon input from the text box
(i) The first question to disappear
(ii) A second question to replace the first question
But I don't know how to make the text box docked to the bottom of the form input the text into the application and make the application continue to accept the responses and keep replacing the original question with a new question, etc. Can anyone help me with this?
|
|
|
|
|
So you are trying to build a wizard type application.
Presumably you have the main form appear when you run the program. Some things you will need.
A list of questions
A list of expected responses/validation rules (eg ask name and get back numbers)
Somewhere to store these usually a database or an XML file
Some mechanism that tells you where you are in the list (index will do)
A container for responses, List<string> will do.
Flow
Form opens
Populate the question list
Set the current index to 0
-----------repeat here
display the text in a label for the question in list[0]
when the user clicks NEXT button validate the text in the textbox
store the response in the response List
increment the current index and repeat until all questions are responded to.
deal with the list of responses, store the info in your preferred device.
You then need to address the back operation as well (then the index is decreased clear all responses above the current one)
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi Teknowizard,
I am going to take your "ui" description literally and assume you really want to display a single question at a time, and I'm going to assume that you intend for the question to be displayed in the main area of the form (i.e., independently of the textbox docked to the bottom). Please correct me if that interpretation is not right.
So you have some method of showing one-question-a-time (textbox ?).
Maybe you have a timer controlling how long the question is visible ... whatever.
Now the user is typing their answer in the textbox : you are going to monitor the user's actions in the TextBox and at some point change the question.
There are many ways to do this, and I'll give you a few hints about design choices you can make with your user input textbox :
1. Multiline property of TextBox : will it be single-line or multi-line
2. AcceptsReturn property of TextBox : what will happen when the user hits the Enter key ?
3. AcceptsTab property of TextBox : what if the use enters tab ?
4. WordWrap property of the TextBox : if multi-line do you want to allow wrapping ?
Once you have experimented with and familiarized yourself with these properties, you can move on to Events of the TextBox.
Note that you could, by setting KeyPreview property of the hosting Form to true, handle key down/up/press events at the Form level.
I suggest you examine the following Events :
1. KeyDown
2. KeyUp
3. KeyPress
And consider the issue of what if the user clicks outside the TextBox : do you wish to make the Focus be restrained so the only thing the user can do is type in the TextBox : examine Events :
1. Enter
2. Leave
If you wish the user to "signal" when they are done entering an answer by some keyboard activity, you are going to need to write a Key Event Handler : start writing one now, and mess around with it, get familiar with KeyCode and/or KeyData properties of the EventArgs passed to a Key Event.
If you wish the user to "signal" they are done by some other means, well, up to you.
A few hours now of experimenting will pay big dividends for you in the future.
best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
modified on Saturday, July 25, 2009 4:56 AM
|
|
|
|
|
Take the jar of baby food out of the cupboard
get a pan of water
remove lid from jar
fill the pan 1/2 full heat on stove with the jar in the water
get a spoon from cutlery draw
when baby food is warm remove from the pan
use spoon to scoop some out
feed yourself
It's a joke Bill, a joke, honest it's a joke.....
Never underestimate the power of human stupidity
RAH
|
|
|
|
|