Is it possible to Enter editmode to a list box in Grid without double click on the cell? - silverlight-4.0

I was following the example in the following link to try out listbox in the grid
http://forums.silverlight.net/forums/t/53435.aspx
it works except that, I need to double click on the cell to enter to edit mode which then switch to listbox. Is there any other way I can enable list box on getting focus?
Thanks,

The is a very simple way to enter a cell in edit mode without using your mouse. First, you need to get the row in which you have the cell. Then you get the cell, then you change the edit mode to True. If you don't have the row, you can find it by using ItemContainerGenerator on the grid with the business object used in that row (from your ItemSource collection). Here is an example of code :
GridViewRow myRow = MyGrid.ItemContainerGenerator.ContainerFromItem(YourBusinessObject);
GridViewCell myCell = myRow.Cells(YourCellIndex);
myCell.IsInEditMode = True;
Hope this help !

Related

Change the color of a selected record in an Access REPORT

My Access REPORT has a text box with the Record ID that looks like a button with an on click event to go to a form for that specific record. This works great, but when I return to the report I cannot see which record was clicked. I want to temporarily change ONLY the record that was clicked until another record is selected.
The reason I want this on a report and not a form is because I want the user to have a quick way to proof read in the format needed to print, and make a change or check a detail if necessary, then update the report AFTER all proof reading and updates are completed and before final print. But with many records on the screen it is easy to lose track of which record you were checking when returning from the form.
I tried:
Private Sub btn_txt_GoToTransaction_Click()
Dim vColor
vColor = RGB(51, 204, 51) 'green
Me.btn_txt_GoToTransaction.BackColor = vColor
DoCmd.OpenForm "Account_frm", acNormal, , "[TransactionID]=" & Me.TransactionID
End Sub
But this does not work because every button turns color not just the selected record.
Any suggestions? Thanks.
This is a great question because there are many benefits to highlighting a row or item in an Access Report. You are not able to just change the button color in one row only, but you can highlight the whole row so the user knows where they were.
Here are two methods to accomplish this:
Method 1 - Click on a Label
This works great in newer versions of MS Access when using Report View. Use a Label Control instead of a Button. You could make the label look like a button if you format it that way. I prefer to stretch an invisible Label across the whole row on top of all the other controls in that row. Then if you click anywhere in the row, it automatically selects that row and then runs whatever code you have in the OnClick Event. This works best if the Label is not linked to a Text Box.
This picture shows an example of how this method looks. You can click anywhere in the row and it highlights that row with the red outline and grey background.
This is very simple and works well but there are a couple disadvantages:
1- You can not change the color of the highlight.
2- If any of the text boxes CanGrow, the row height may be higher then the Label and create areas where the invisible label doesn't capture your click.
3- Clicking on a Text box does not work for this method.
Method 2 - Change Color of a Text Box
In order to just highlight one row or one piece of data in a report, we can use the "FormatConditions" property. This is the same as Conditional Formating from the MS Access design interface but we are going to change it programmatically on the fly. You can't do this with a button or label - it needs to be a Text Box with unique data, such as your TransactionID.
This picture shows an example of how this method looks. You can set the color of the highlight if you follow the steps below.
STEP 1) I recommend that you add a text box to your report that stretches from the left to the right, set the Back Color and Fore Color to White, set the Control Source to TransactionID, and set the Name to TransactionID. Then right click on this text box and select Position > Send To Back. This works best if the other text boxes and labels on the report have a transparent background.
STEP 2) Add this code:
Private Sub HightlightRow(intRowID As Integer)
With Me.TransactionID.FormatConditions
.Delete
With .Add(acFieldValue, acEqual, intRowID)
.BackColor = vbGreen
.ForeColor = vbGreen
End With
End With
End Sub
STEP 3) Also change your button code to call this subroutine like this:
Private Sub btn_txt_GoToTransaction_Click()
HightlightRow Me.TransactionID.Value
DoCmd.OpenForm "Account_frm", acNormal, , "[TransactionID]=" & Me.TransactionID
End Sub
STEP 4) I like to set it up so if the user clicks anywhere in the row, it will pop up with a modal with more detail regarding that row. Also, the user can't make any changes to the data in the Report View, so I use the pop up modal to allow changes. To accomplish this, I do a couple more things:
First, we need to add the code to the OnClick event for every control in that row. Ofcourse, each OnClick event will simply can that subroutine HightlightRow Me.TransactionID.Value
Second, if the user clicks on a Text Box, the Text Box gets the focus and hides the highlight. Therefore, I like to set the focus to something else. In your case, you could set the focus to the button by adding this line to the end of the HighlightRow subroutine: btn_txt_GoToTransaction.SetFocus
In my case, I am not using a button, so I set up a tiny Text Box with = " " (just an equal sign a space in quotation marks) as the Control Source. Then I position this tiny Text Box to the far right. And in the HighlightRow subroutine, I set the focus to this textbox.
STEP 5) You may also want a button or method of removing the highlight. To do that simply have the code run this line:
Me.TransactionID.FormatConditions.Delete

How to force match Combobox RowSource row by setting its Text property?

On the shop floor, a virtual (touch) keyboard form with larger buttons is used to enter text into TextBoxes and ComboBoxes.
This works fine, and combobox text is set correctly, however the RowSource is not matched as it would be when you type directly into the ComboBox with a physical keyboard. The entire list is displayed as if you had just pressed the dropdown button without typing a character.
In the example below, there is a Stefan in the list, but that row is not looked up.
I've tried SetFocus, Requery, Refresh, Dirty, and calling _AfterUpdate, in combinations and with DoEvents, to no avail.
I've even tried to select, Cut, and Paste the text (but even setting SelStart and SelLength to correct values does not select it, so I'm assuming it cuts and pastes a range of zero characters). If I could make the text-selection work, I could probably get this to work.
Dim ctrlPrevious As Control
Set ctrlPrevious = Screen.PreviousControl
ctrlPrevious.SetFocus
ctrlPrevious.text = sTemp
ctrlPrevious.SelStart = 0
ctrlPrevious.SelLength = Len(sTemp)
ctrlPrevious.Cut
ctrlPrevious.Paste
Is there a way to force the AutoComplete behavior?
Use SendKeys to mimic the normal keyboard beheviour instead of all the above code.
So in your btnPressed_Clicked event
Dim ctrlPrevious As Control
Set ctrlPrevious = Screen.PreviousControl
ctrlPrevious.SetFocus
SendKeys btnPressed.caption

Combo box's last value stays activated even if .removeitem has removed it

I have a situation where combobox's last value stays in the screen even if it has been removed via VBA.
I was using the method
cboBox.Removeitem "Drafter"
but here's what I would see
i've try cboBox.Requery afterwards, but no luck.
any help would be appreciated. thanks.
UPDATE:
I tried changing the combo box's source type from Value list to Table/Query, and just .requery after the values are updated. The same problem presists. Access has seemed to set "Drafter" as the default value now.
The Combo Box retains its .Value even after the underlying Item has been removed from the list. That's why it still shows up in the (top) text box portion of the control even after it has been removed from the drop-down list portion. You could try this:
Dim itemToRemove As String
itemToRemove = "Drafter"
Me.cboBox.RemoveItem itemToRemove
If Me.cboBox.Value = itemToRemove Then
Me.cboBox.Value = Null
End If

Extend the properties of datagridview and its cell

I am working on the datagridview now days. And I have to assign some custom properties to the datagridview which I am able to do. problem comes when I want to extend the properties of the cell. for example I already have my custom textbox control which user can set the behaviour like if its numeric or alphanumeric, allow negative, allow decimals etc etc. which works fine. Now I want to include that textbox control in my extended grid. So user can set all those properties while adding columns.
First of all is it possible? If yes then any tutorial or help please.
thanks in advance.
I'm not fully certain so you may want to keep looking, but as far as I know you have to manually set each property of the text box to what you want. There isn't a copy all cell style settings to textbox call you can make.
Public Sub funwithDGVs()
Dim DataGridView1 As New DataGridView
Dim DataGridViewCell1 As DataGridViewCell
DataGridViewCell1.ForeColor = Color.Aquamarine
DataGridView1.Item(0, 1).Style.ForeColor = DataGridViewCell1.ForeColor
TextBox1.ForeColor = DataGridViewCell1.ForeColor
End Sub

Determine if an item is selected in a listview box

Using VB.net 2010 i am trying to figure out if an item was selected or not. Reason being is that if the user clicks on an item and pushes a button then everything works just fine. However, if the user selects an item and then clicks on a blank spot on the bottom of the listview and then clicks the button then it crashes.
My code is this:
If (lstMaster.SelectedItems(0).SubItems(1).Text) Is Nothing Then
MsgBox("test")
End If
Any help would be great! :o)
David
Ensure that something is selected first by checking that SelectedItems is not empty.
lstMaster.SelectedItems.Count > 0
check lstMaster.SelectedItems(0).Selected
Not sure if I've understood you correctly - Try using the ListView MouseMove event and check that lstMaster.SelectedItems.Count > 0 if you want to change the Enable property of a Button based on whether a row has been selected or not within your ListView control.
Use this checking with "If/EndIf" construction:
ListView1.Items(0).Selected = True