How to check the selected Items - vb6

Using VB6
In the Form, i am having 2 list box name as lstDivison, lstDepartment
Code
For I = 0 To lstDivision.ListCount - 1
If lstDivision.Selected(I) = True Then
Filter = ""
Filter = lstDivision.List(I)
Divison
Else
ViewAll
End If
Next
For I = 0 To lstDepartment.ListCount - 1
If lstDepartment.Selected(I) = True Then
Filter = ""
Filter = lstDepartment.List(I)
Department
Else
ViewAll
End If
Next
Above code is working, but i want to know which listbox value is selected.
Conditon
If lstDivison list item is selected then it should not check the lstDepartment, if lstDepartment list item is selected then it should not check the lstDivison...
Code like this...
If lstDivison.selected = true then
some code
ElseIf lstDeartment.Selected = true then
some code
Else
Some code
End If
How to do this.
Need VB6 Code Help

One way to solve this is to ensure that only one of the listbox controls has a selected value at each time, by letting the listboxes clear the selection from the other listbox when selected. This makes it somewhat clearer to the user what values to expect from the filter, since there will only be selected values in one listbox at a time.
To do this, you can add this code:
private sub lstDepartment_Click()
For I = 0 to lstDivision.ListCount - 1
lstDivision.Selected(I) = False
Next
End Sub
private sub lstDivision_Click()
For I = 0 to lstDepartment.ListCount - 1
lstDepartment.Selected(I) = False
Next
End Sub
After this, your current code will work.

Related

Visual Basic 6.0 disable checkbox on datagrid

I have a datagrid table with a text on first column and a checkbox on second column. I would like to disable this checkbox when first column value is "Others". Is this possible?
Thanks in advance!!
You can set properties for the entire grid. You can set properties for an entire column. You can even set a few properties for a cell, but one of those properties is not an enabled property. The best I was able to come up with was responding to the following event:
Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
If DataGrid1.Col = 1 Then
DataGrid1.Col = DataGrid1.Col - 1
If DataGrid1.Text = "Others" Then
DataGrid1.Col = LastCol
DataGrid1.Row = LastRow - 1
Exit Sub
End If
DataGrid1.Col = DataGrid1.Col + 1
End If
End Sub
This logic prevents focus on a cell in column 2 if column 1 is "Others". Keep in mind that rows and columns are 0-based.

Select an item by name instead of id in VBS

I have recorded a script on SAP that runs on CITRIX. Everything worked fine until some items were added to the window that the right item was selected to filter the columns. I guess the reason is that the proper item (e.g. MATART in the shown picture) moved down and it was not the same row, order etc.
I was wondering whether there is a way to select the item by its name instead of id?
This is the part of the script with the line that selects the items:
session.findById("wnd[0]/tbar[0]/okcd").text = "/nzm082"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/tbar[1]/btn[33]").press
session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").currentCellRow = 1
session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").selectedRows = "1"
session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").clickCurrentCell
session.findById("wnd[0]/tbar[1]/btn[45]").press
You could test the following.
for example:
...
session.findById("wnd[0]/tbar[1]/btn[33]").press
set myLayout = session.findById("wnd[1]/usr/cntlGRID/shellcont/shell")
Rows = myLayout.RowCount
For i = 0 to Rows - 1
myVariant = session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").getCellValue (i, "VARIANT")
if myVariant = "MTART" then
session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").currentCellRow = i
session.findById("wnd[1]/usr/cntlGRID/shellcont/shell").clickCurrentCell
Exit For
end if
next
session.findById("wnd[0]/tbar[1]/btn[45]").press
...
Regards, ScriptMan

Show/Hide ColumnGroups with a mix of hidden and displayed columns

I've got a RadGrid with programmatically generated columns, including a variable number of column groups. Each of the column groups contains four columns, two that are displayed and two that are not.
Above the RadGrid I have a series of checkboxes, one for each column group. The goal is to have the user check or uncheck the boxes depending on what columns they wish to see. Currently I am setting the columns' Display properties when a checkbox's checked value is changed by using radgrid.Columns.FindByUniqueName("columnName").Display. However the column group itself cannot be accessed this way. As it is, the column groups disappear when all their child columns disappear, but they do not reappear when their child columns are displayed, causing the headers to become misaligned.
Relevant code:
'Defining the grid
Dim radgrid As RadGrid
radgrid = New RadGrid()
Dim i as Integer = 0
For Each r As DataRow In subTable.Rows
Dim colGroup As GridColumnGroup = New GridGroupColumn()
radgrid.MasterTableView.ColumnGroups.Add(colGroup)
colGroup.HeaderText = r.Item("Name")
colGroup.Name = "colGroup" & i
Dim colID As GridBoundColumn = New GridBoundColumn()
radgrid.MasterTableView.Columns.Add(colID)
colID.ColumnGroupName = "colGroup" & i
colID.DataField = "id" & i
colID.HeaderText = "ID"
colID.UniqueName = "id" & i
colID.Display = False
Dim colScore As GridBoundColumn = New GridBoundColumn()
radgrid.MasterTableView.Columns.Add(colScore)
colScore.ColumnGroupName = "colGroup" & i
colScore.DataField = "score" & i
colScore.HeaderText = "Score"
colScore.UniqueName = "score" & i
i += 1
Next
'Checkbox CheckedChanged sub
If selectedButton.Checked = True Then
radgrid.Columns.FindByUniqueName("colScore" & selectedButton.Value.ToString()).Display = True
Else
radgrid.Columns.FindByUniqueName("colScore" & selectedButton.Value.ToString()).Display = False
End If
Ideally I'd like to do something like radgrid.MasterTableView.ColumnGroups.FindGroupByName("colGroup" & selectedButton.Value.ToString()).Display = False but there is no Display property for that and the Visible property is ReadOnly. I've also tried re-setting the ColumnGroupName of the columns after setting them to display, but that also does not work.
I'm guessing the fact that I have hidden columns is what's making this more complicated than it should be, but is there a way to get this to work with hidden columns?
The solution actually turned up when I was working on a somewhat unrelated issue.
Calling radgrid.Rebind() after changing the value of the Display property causes the group column headers to disappear and reappear as desired.
Protected Sub button_CheckChanged()
If selectedButton.Checked = True Then
radgrid.Columns.FindByUniqueName("colScore" & selectedButton.Value.ToString()).Display = True
Else
radgrid.Columns.FindByUniqueName("colScore" & selectedButton.Value.ToString()).Display = False
End If
radgrid.Rebind()
End Sub

compare datatable and remove duplicates in vb.net

am using two datatable named as dnddatatable and dtdup . it contains set of phone numbers . I want to compare 2nd datatable with first datatable and remove the values from datatable1(name as dnddatatable)values which are equal to 2nd datatable name as(dtdup).
data in the datatable as follows.
dnddatatable(data table1)
phone
9865015695
9840903331
98668625
800971868
809679532
837445478
dtdup(dtata table2)
phone_numbers
9865015695
9840903331
result dnddatatable(data table1)
98668625
800971868
809679532
837445478
I answered a pretty similar question time ago, the idea is exactly the same
For i As Integer = 0 To dataset.Tables(0).Rows.Count - 1
Dim found As Boolean = False
For j As Integer = 0 To dataset1.Tables(0).Rows.Count - 1
If dataset.Tables(0).Rows(i)(0).ToString = dataset1.Tables(0).Rows(j) (0).ToString Then
found = True
End If
Next
If found = False Then
'here you are getting the right result in each loop
'in this example i'm showing the result in a textbox
'just change the instruction and write them in your note pad or wherever you want to
MsgBox(dataset.Tables(0).Rows(i)(0).ToString)
End If
Next

Make only one row show after search in FlexGrid VB6

So i have FlexGrid in my VB6 project I'm working on. It has names on each row, and I have a drop down so the user can select what name they want to see more info for, here is what I have.
Dim target_name As String
Dim r As Integer
' Get the name.
target_name = Combo1
If Len(target_name) = 0 Then Exit Sub
' Search for the name, skipping the column heading row.
target_name = LCase$(target_name)
For r = 1 To MSFlexGrid1.Rows - 1
If LCase$(MSFlexGrid1.TextMatrix(r, 0)) = _
target_name Then
' We found the target. Select this row.
MSFlexGrid1.Row = r
MSFlexGrid1.RowSel = r
MSFlexGrid1.Col = 0
MSFlexGrid1.ColSel = MSFlexGrid1.Cols - 1
' Make the row visible.
MSFlexGrid1.TopRow = r
Exit Sub
End If
Next r
That works well, but it shows everything below that name too, I would like it to single out only the name selected.
Any help would be great.
What's the data source of your grid? You can place the filter on the data grid data source, so that as the user chooses the name from your drop down only the selected persons details are returned from the datasource to the grid.
Not exactly what you were asking, but its how I would achieve the result you are wanting.
P.S. I have used FlexGrid in VB6 and I don't know of a way to do what you are asking on the grid (might be there but I never noticed it).

Resources