Is it possible to set vb.net datagridview cell alignment without modifying whole column? - vb.net

I am trying to set the alignment of a specific cell in a row/column to be right aligned. However I do not want to set the whole row, or whole column to right aligned. Is it possible to set the cell only? From what I've seen online I'm starting to think it isn't possible.

You would need to hook up to the RowDataBound event. This fires as each row is databound. Check that the row is a data row (as opposed to a header or footer). Then check the value in the column you are interested in. If the value meets your criteria for right justification then apply that to the column in question.
Note if you are using AlternateItemTemplate then check both Item rows and AlternateItem rows.
I've used this method to say change the backround colour of values that fall outside a range.

Related

Is There a More Efficient Way of Determining Whether a Table Row Spills Over Into the Footer Than Looping Through All Cells?

I'm currently using Microsoft Word 2016 VBA to programmatically set the AllowBreakAcrossPages setting so that if a row's contents overlaps the footer contents, I toggle the setting so that the row can break across pages. To solve this issue, I'm thinking about looping through all the cells of each table in the document and get the wdVerticalPositionRelativeToPage.Information of the last characters in each cell and comparing it to the footer's height relative to the page. If the last character's height is greater than the footer's, I set the row to break across pages. You can imagine that this is taking a while in a document that has many tables and cells. Is there a more efficient way to know if the row contents overlap the footer contents than looping through each cell in the row to see if a cell is causing the row to overlap the footer?
I tried using the row height property but discovered that if the HeightRule property of the specified row is wdRowHeightAuto then that means I can't access the row height via VBA.
I discovered that it's possible to use wdVerticalPositionRelativeToPage.Information with a row by row comparison of the prior and next rows like described in another posting - https://stackoverflow.com/a/14753231/4372244.
The only problem with that solution is that it doesn't work for the last row in a table or if it's the last row on a page.
Therefore, I'm examining a cell by cell solution.

How to set the cell value for displayed cells only?

I have some data I want to display in a StringGrid. This data contains many rows with some pretty static columns but also two columns that need web-API lookups and take some time to gather. SO when I try to set these cells in the OnShow of the StringGrid (or any other "Init") I get a long delay until the cell values are set.
What I would like to do is only look up the values for those cells that are currently displayed (and not all of them at once).
How Do I find out which rows are currently displayed? Is there an event I can use?

How to use vba to filer a column using value from a specific cell

I want to use a macro to filter columns in a table. I want to filter for values that are higher than a value I want to put in cell, to be able to easily change the filter. Does someone have a trick for doing this with vba?
Many thanks, Bram
Record a macro whilst filtering a table on a column value. You would right click on the table column header of interest whilst recording the code and select Number_Filters > Greater Than and enter your desired number. That would give you the outline code. You can then amend the code to pick up the desired value from a specified cell. If applying filter to multiple columns record macro whilst doing this process over several columns.
Thank you for you answer. I tried this already, but I could not get the macro to pick from a specific cell. If I stored the value of the specific cell under as 'value' and put that in the outlined code, it would just do Greater Than value.. DO you have shortcut for this?
Thanks!

How do I check to which row area field a cell in a pivottable belongs to?

I have a PivotTable in compact form layout (default layout) with multiple row area fields. This results in multiple grouping levels with buttons to collapse or expand rows.
I want to modify a cell depending on the grouping level the row is in.
How can I check in which row the cell is in?
The only idea I had so far was to check the value of the leftmost cell in the corresponding row and compare it with each item from each rowField.
But I guess there is a smarter way?
It took me a while. But at the end I just needed PivotCell.RowItems.Count
Depending on the Count result I can new manipulate the cell.

Adding a row (not a column) of a type (checkbox,dropdown) in datagridview

I have a datagridview that is only two or three rows long. It has 7 text columns, one for each day of the week (Monday - Sunday). I'm creating a scheduler, so basically on the left side I have added text to the row headers to assign to it. I.e. Enabled (let's say for Tuesday), start time and end time. This allows the user to schedule as need be.
Here's a picture of it right now:
What I want to do is possibly change the enabled row, or the start/end time to a particular type. So the enabled will be a checkbox and the start/end times will be drop down menus instead of these text boxes.
My question is, what's the "best" way to add a row of a certain type? Obviously columns are done easily, but is there a common method for a row type other than looping through and adding individual cells of that type to the datagridview?
The type of each cell can only be pre-determined by the column, not the row. As a result, you're going to have to add each cell individually. You can actually put a cell of any type anywhere you want. You simply create a cell of the desired type and assign it to the Item property of the grid, e.g.
myDataGridView(columnIndex, rowIndex) = newCell
You will simply have to use a For loop to do that for each valid column index with a single row index. Note that you'll have to create a new cell for each column, not reuse the same one.