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
Related
My code takes a file name from TextBox1, opens that file and indexes through all the unique values in column B. It then takes a second file, file name in TextBox2, and filters it based on the current index from the first file. It then takes the filtered results and copies them to a sheet in the new workbook. A new sheet is then generated in the new workbook to paste the next filtered result.
My issue is that I have many rows of data and for some reason the filtered data is not be selected after many iterations. My program selects all filtered data when it starts, but at some point it just begins selecting the headers instead of all the visible cells. Let me know if I am missing something or if there is a quick workaround. Thank you.
Sub NewFileGenerate()
Dim I As Integer
Dim N As Integer
Dim X As Integer
Dim IndexedCell As String
X = 1
Windows(TextBox1.Value).Activate
'Need to count only populated cells
I = Sheets(1).Columns(2).Cells.SpecialCells(xlCellTypeConstants).Count
Set Newbook = Workbooks.Add
For N = 2 To I - 1
Application.CutCopyMode = True
Windows(TextBox1.Value).Activate
IndexedCell = Cells(N, 2).Value
Windows(TextBox2.Value).Activate
With Sheets(1)
With .Range("A1", "Z" & I - 1)
.AutoFilter Field:=5, Criteria1:=IndexedContract
.SpecialCells(xlCellTypeVisible).Copy
End With
End With
Newbook.Activate
ActiveSheet.Paste Destination:=Sheets(X).Range("A1:Z1")
Cells.Select
Selection.Font.Size = 10
Cells.EntireColumn.AutoFit
Cells.Select
X = X + 1
If X > 3 Then
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Sheet" & X
End If
Application.CutCopyMode = False
Next N
End Sub
I'm guessing that your source worksheet (textbox2.value) has more rows than your index worksheet (textbox1.value). You set I equal to the number of rows in your index worksheet, then you tell the autofilter to only use that number of rows. You need to change the line "With .Range("A1", "Z" & I - 1)" so it picks up all of the rows in your source worksheet.
I have this query below and I want to show items that sold depending on sales_id without repeat the old ids. And another question how to make a combo box data grid view:
Private Sub filldatagrid()
Dim myTableName As String
myTableName = txtid.Text
winclass.filldatagrid(DataGridView1, "select inventory.inv_name,sales_data.sales_id,sales_data.quantity,sales_data.sum_total from sales_data,inventory where sales_data.inv_id=inventory.inv_id ")
DataGridView1.Columns(0).HeaderText = "ID"
DataGridView1.Columns(0).Visible = True
DataGridView1.Columns(1).HeaderText = "name"
DataGridView1.Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
End Sub
I'm currently doing automation testing and need to write a dynamic value to an existing excel document in a specific column, this is what I have so far. Forgive I'm a novice
Sub WriteTRNtoExcelDoc
Dim fileName, sheetName
fname = "<Path_To_The_File>"
sheetName = "Sheet1"
Set app = Sys.OleObject("Excel.Application")
Set book = app.Workbooks.Open(fname)
Set sheet = book.Sheets(sheetName)
' What do I do next to add a value to a specific column or cell in this
' spreadsheet?
End Sub
Thanks in advance!
You create an Excel instance in a VBScript with
CreateObject("Excel.Application")
An already running Excel instance can be grabbed with
GetObject(, "Excel.Application")
In a worksheet you can access cells by using the Cells property:
Set app = CreateObject("Excel.Application")
app.Visible = True
Set book = app.Workbooks.Open(fname)
Set sheet = book.Sheets(sheetName)
sheet.Cells(2,3).Value = "foo"
Edit: If you need to find the first empty cell in a given column, you can use something like this:
row = 1
Do Until IsEmpty(sheets.Cells(row, 3).Value)
row = row + 1
Loop
sheet.Cells(row, 3).Value = RemPropValue
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.
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).