DevExpress XtraGrid GroupRow, CheckEdit Interactions Possibilities - vb.net

Currently, I am displaying an XtraGrid that contains Group Rows. I have a "Select All" DevExpress.XtraEditors.CheckEdit control (which is different from this elusive "Select All" check box control I am reading about in the documentation). It is different for a reason: I want the check box to do something other than "Select All" (which comes in only three different varieties according to the DevExpress Docs.).
I want a user to be able to do one of two things with the CheckEdit control. [1] If no Group Rows are expanded, I want to select all Group Rows. [2] If one or more Group Rows are expanded, I only want to select the expanded rows.
Presently, I am able to manipulate the controls to do only one of the two things (see code). My question is twofold: is this possible; and, if so, how would I go about it?
Here is my code that does the second of the two 'things' described above:
'If the CheckEdit control is checked:
xtraGrid.SelectAll()
Dim rowHandles() As Int32 = xtraGrid.GetSelectedRows()
If rowHandles.Count > 0 Then
For Each RowHandle As Int32 In rowHandles
If xtraGrid.IsGroupRow(RowHandle) Then
xtraGrid.UnselectRow(RowHandle)
End If
Next
End If
As you can see, all this really is just a work around. There is also presumably more overhead than needed in my calling .GetSelectedRows(). I am just attempting to sort through the row types in order to keep the row selected or .UnselectRow()

You can use GridView.GetRowExpanded method to check whether a specific group row is expanded. For iterating through visible rows you can use GridView.RowCount property. To get row level just use GridView.GetRowLevel method. Also you need to check wether a row is new item row or is filter row by using GridView.IsNewItemRow method and GridView.IsFilterRow method. For all of this methods you need to get Row handle by using GridView.GetVisibleRowHandle method. When you are working with selection is better to use GridView.BeginSelection method and GridView.EndSelection method outside of your code.
UPDATE: If you want to select hidden rows within a collapsed group then you can use GridView.GetChildRowCount method and GridView.GetChildRowHandle method to get all hidden rows.
Here is some sample code that is performing your two things together:
Private Sub SomeSub
If xtraGrid.GroupCount = 0 Then
xtraGrid.SelectAll()
Exit Sub
End If
xtraGrid.BeginSelection()
xtraGrid.ClearSelection()
Dim isExpanded As Boolean = False
For rowVisibleIndex = 0 To xtraGrid.RowCount - 1
Dim rowHandle As Integer = xtraGrid.GetVisibleRowHandle(rowVisibleIndex)
If xtraGrid.IsNewItemRow(rowHandle) Then
Continue For
End If
Dim level As Integer = xtraGrid.GetRowLevel(rowHandle)
If level = 0 Then
If Not isExpanded Then
isExpanded = xtraGrid.GetRowExpanded(rowHandle)
If isExpanded Then
xtraGrid.ClearSelection()
Else
xtraGrid.SelectRow(rowHandle)
End If
End If
Else
xtraGrid.SelectRow(rowHandle)
'Update: select hidden rows
If xtraGrid.IsGroupRow(rowHandle) And Not xtraGrid.GetRowExpanded(rowHandle) Then
SelectRowHierarchy(rowHandle)
End If
End If
Next
xtraGrid.EndSelection()
End Sub
Private Sub SelectRowHierarchy(rowHandle As Integer)
Dim childCount As Integer = xtraGrid.GetChildRowCount(rowHandle)
For childIndex As Integer = 0 To childCount - 1
Dim childRowHandle As Integer = xtraGrid.GetChildRowHandle(rowHandle, childIndex)
xtraGrid.SelectRow(childRowHandle)
If xtraGrid.IsGroupRow(childRowHandle) Then
SelectRowHierarchy(childRowHandle)
End If
Next
End Sub

Related

How to alphabetize fields in Unhide Columns dialog box in Access VBA?

I have a ton of columns in this table and I want them to be alphabetized so they are easier to find.
I remember seeing how to do this in a Youtube video but I can't find it for the life of me. Below is an example of the code I am using in multiple datasheet type forms. I'm not sure what needs to be added in to make these field lists alphabetize
Private Sub showHideColumns_Click()
frmInventoryListSubform.SetFocus
DoCmd.RunCommand acCmdUnhideColumns
End Sub
The "columns", the controls, have both a name and, optionally, a caption.
So, in your form, you can run this code to list these:
Private Sub ListColumns()
Dim Control As Control
Dim Index As Long
For Index = 0 To Me.Controls.Count - 1
Set Control = Me.Controls(Index)
If Control.ControlType <> acLabel Then
Debug.Print Index, Control.Name, Control.Properties("DatasheetCaption").Value
End If
Next
End Sub
May return a result like this:
0 StipendNo Student Number
2 PayNo Pay Number
4 PayDate
6 PayAmount

Determine if an integer is a member of a list of integers

I need to determine if a particular integer does not exists in a datagridview column. I assume I should create an array of the integers from the dgv column, and then compare if the integer exists in the array. However, there is perhaps an easier or simpler way.
I have looked at many articles but none of them resolve my task. Some of the Stack Overflow articles show similar solutions but I can't quite determine what to do.
For a = 0 To Dgv1.RowCount - 1
If Not Dgv1(1, a).Value = Dgv0(1, m).Value Then
Dgv0(1, Dgv0.RowCount - 1).Value = Dgv0(1, m).Value
End If
Next
I hope to compare an integer with a column of integers in a datagridview and if it is present do nothing but if is not present add it to the datagrid view
Are you using wpf? If yes, create a model.
provide a checking mechanism at the setter, use observablecollection or list then bind it to the datagirdview
Get the row and column of the datagridview
then compare (means condtional statement) to the variable you wanna check
and of course it should be inside of loop, loop count is equal to the count of rows you have in the datagridview.
Here's an example code:
Dim column As String = "YourColumnNameHere"
' Assuming 2 is the number you wanna compare
Dim value As Integer = 2
For row As integer = 0 to dataGridView.RowCount - 1
If dataGridView.Rows(row).Cells(column).Value = value Then
' Do something here
Else
' Do something here
End If
Next

Single selection CheckedListBox control

I have a CheckedListBox control.I want to limit it's selection property to one means now a user can select more than one item in the control, need to limit this property to single selection only.
For example, Let's CHKListsolutions has following items
Google
Bing
Yahoo
Normally we can select 3 of them because of an obvious reason.
How to make this CHKListsolutions to select only one item in the list.
for example, I select Google and for some reason I want chnage the selection so I will select Yahoo then my last selection should unchecked and new one should be checked
I have checked in the resource for a property but in vain.
Any help would be very much appreciated
Private Sub CHKListsolutions_MouseClick(sender As Object, e As MouseEventArgs) Handles CHKListsolutions.MouseClick
Dim idx, sidx As Integer
sidx = CHKListsolutions.SelectedIndex
For idx = 0 To CHKListsolutions.Items.Count - 1
If idx <> sidx Then
CHKListsolutions.SetItemChecked(idx, False)
Else
CHKListsolutions.SetItemChecked(sidx, True)
End If
Next
End Sub
In MouseClick event you'll get the currently selected index of the item in the control(sidx) use this sidx to loop through number of items in the control and uncheck checked item that is not equal to the current index using SetItemChecked method
Use Radio Button instead of Checkedlistbox

Visual Basic: How can I get all selected Values from a Listbox (Selectionmode Multisimple) using a Loop?

I'm using a Listbox in my program which is coupled to a dataset. Now I want to select some items in Runtime and get all the values behind those selected items. The values represent the ID's from the Database Entities. I need them for some SQL-queries.
So this is what I've already tried:
For x = 0 To ContracttypeListBox.Items.Count() - 1
If ContracttypeListBox.GetSelected(x) = True Then
MsgBox(ContracttypeListBox.SelectedItems(x)(ContracttypeListBox.ValueMember))
End If
Next
I found the function in the MsgBox using my friend Google. Actually it works quite well but only if I select all items (starting with the first one) in the Listbox. An unselected item among them will cause a System.IndexOutOfRangeException. The same Problem occurs when I don't select the first item in the list but all the others.
Thanks to Plutonix
This is the solution:
For x = 0 To ContracttypeListBox.SelectedItems.Count() - 1
If ContracttypeBox.SelectedItems.Count() > 0 Then
MsgBox(ContracttypeListBox.SelectedItems(x)(ContracttypeListBox.ValueMember))
End If
Next x
You can use ListBox.SelectedItems.
For Each item In ListBox1.SelectedItems
Dim id As Integer = Val(item.ToString)
Next

How to find the number of expanded/collapsed master rows and grouped rows in a DevExpress GridView?

I am currently using DevExpress 10.2 within Visual Studio 2010. In a previous question I was trying to print the current user view of a DevExpress GridControl with the user's choice of expanded or collapsed master rows and/or group sections. I was told this was not possible at this time. I have now decided to use the following code:
gvPOinvoiceBanded.OptionsPrint.ExpandAllGroups = False
gvPOinvoiceBanded.OptionsPrint.ExpandAllDetails = False
when I want it to be completely collapsed while printing as by default these are set to true.
I was just wondering if there is someway to check either the total number of expanded master rows or the total number of collapsed master rows. I would also like to do the same thing for the groups as you can have the groups expanded while the master rows are not.
You can get the number of expanded group rows using a loop like this:
Dim ExpandedGroupCount As Integer = 0
Dim Handle As Integer = -1 'group rows have negative row handles
Do Until GridView1.GetRow(Handle) Is Nothing
If GridView1.GetRowExpanded(Handle) Then
ExpandedGroupCount += 1
End If
Handle -= 1
Loop
'Do whatever with expanded group count
MsgBox(String.Format("Number of Expanded Group Rows: {0}{2}Number of Group Rows: {1}",
ExpandedGroupCount, Math.Abs(Handle + 1), Environment.NewLine))
Similarly, you can do this to get the count of expanded master rows:
Handle = 0
Dim ExpandedMasterRowCount As Integer = 0
Do Until GridView1.GetRow(Handle) Is Nothing
If GridView1.IsMasterRow(Handle) Then
If GridView1.GetMasterRowExpanded(Handle) Then
ExpandedMasterRowCount += 1
End If
End If
Handle += 1
Loop
MsgBox(String.Format("Number of Expanded Master Rows: {0}", ExpandedMasterRowCount))
Of course, if you are only checking so that you can see if you need to set the collapse this probably isn't worth the effort. There is no direct property that provides the counts you are looking for.
You could also probably use the events that fire when rows are collapsed and expanded to track the count as it changes. You have to be careful with that though because the event only fires once when expand or collapse all happens. So if you go with that method be sure to check the rowHandle in the event arguments parameter for GridControl.InvalidRowHandle. That is the value used in the case of collapse or expand all.