Bold a certain value of a specified column in a specific grid - vb.net - vb.net

I have miniature problem. First, I'm using vb.net.
What I want is to get the same value from a column that I could only those values thicken and in some way to express more than in other in my gridview (devexpres grid).
In my picture you can see the name of the first column and the cell values. I want only the name 'KLASA' TO CHANGE IN THE SAME NAME ONLY BOLD (for each cell named 'KLASA').
Thank you!

You should use the RowCellStyle event:
Using the example found on that page, you can get the class that makes up the row like this:
Dim View As DevExpress.XtraGrid.Views.Grid.GridView = sender
Dim ClassX As MyClass = View.GetRow(e.RowHandle) 'This would be the type of data you set as the datasource for the grid
Then read you value or do whatever you need to here to figure out if it should be bold and set the appearance like this:
e.Appearance.Font = New Font(f.FontFamily, f.Size, FontStyle.Bold)

Related

VB stretch DataGridViewImageColumn images programmatically

What I am doing
I am developing a VisualBasic application where the GUI is separated from the data manipulation (frontend and backend). This particular piece of code keeps track of the Serial Numbers already measured and displays them in the Form as a DGV with the serial number and an image or not.
My code
In a class that the GUI Form instantiates, my data is stored in a DataTable with a BindingSource, with the second column displaying an Image when I tell it to in the program (Nothing in the beginning):
Public SerialNumbersBindingSource As New BindingSource
Public SerialNumbersDataTable As New DataTable
(...)
SerialNumbersBindingSource.DataSource = SerialNumbersDataTable
SerialNumbersDataTable.Columns.Add("Serial", Type.GetType("System.String"))
SerialNumbersDataTable.Columns.Add("Pass", MyImage.GetType)
In my GUI Form code, a DataGridView has its DataSource set to the former DataTable:
DataGridViewSerialNumber.DataSource = MyObject.SerialNumbersDataTable
By just updating the DataTable in my class, the DataGridView updates automatically to reflect the current state of it. I do it like:
SerialNumbersDataTable.Add(CurrentSerial, MyImage)
The results I get
The code works, so I can modify and access the DataTable and the DataGridView autoupdates. But the images are not stretching, so I can only see a small part of them.
What I need
I need the second column named "Pass" in DataGridView to stretch the images.
What have I tried
If I access the column, it is treated like a DGVColumn and not a DGVImageColumn, so the Layout operation fails.
DataGridViewSerialNumber.Columns("Pass").DataGridViewImageCellLayout.Stretch
Microsoft's Docs page tells me to do this, which treats the columns like DGVImageColumn as I need "Pass" to. It fails because the first column is a Text one, not image.
For Each column As DataGridViewImageColumn In DataGridViewSerialNumber.Columns("Pass")
column.ImageLayout = DataGridViewImageCellLayout.Stretch
Next
Also I have tried creating a local DGVImageColumn, modify it and write it onto the original column, but it is read-only.
Dim imageColumn As DataGridViewImageColumn
imageColumn = DataGridViewSerialNumber.Columns("Pass")
imageColumn.ImageLayout = DataGridViewImageCellLayout.Stretch
DataGridViewSerialNumber.Columns("Pass") = imageColumn
I have also tried to do it from the designer. If I click the DGV, arrow to the right and 'Edit Column', I can create the two columns and setup Pass as ImageColumn with Stretched Layout. But when I set up DGVSerialNumbers.Datasource to my DataTable, it adds the DataTable's columns to the DGV's.
Failed DGV with columns added in designer
It's time for you to learn how to cast. If you want to access one column then don't use a loop. Simply access the column you want and then cast it as the type you want to use it as. You also need to actually assign the appropriate value to the appropriate property.
DirectCast(DataGridViewSerialNumber.Columns("Pass"), DataGridViewImageColumn).ImageLayout = DataGridViewImageCellLayout.Stretch
If you want to break that up for clarity:
Dim imageColumn = DirectCast(DataGridViewSerialNumber.Columns("Pass"), DataGridViewImageColumn)
imageColumn.ImageLayout = DataGridViewImageCellLayout.Stretch
Also, be aware that Stretch will not retain the original aspect ratio, so you might want to use Zoom instead.

How to use the value not displayed by a dropdown when connected to access database

My program uses a database in access which consists of BreedID and BreedName. I have a dropdown box in vb.net which shows the name for the user to select, however in my code I would like to store the ID related to that name so that I can send it over to the access database using oledb. Currently this is what it looks like:
Dim BrVar As String = Breed.SelectedItem.Text
But that isn't working! Please help!
You can add hidden columns to your dropdown box, it may already exist. The first column in a dropdown box is column(0) and you can set the width to 0cm. This can be for the ID value. Leaving column(1) for the Name value.
Then you can use Breed.SelectedItem.column(0)
The first thing to do is on the Data tab set up your rowsource to SELECT both the BreedID and BreedName fields (in that order). Then make sure bound column is set to 1.
Then on the Format tab set Column Count to 2 and Column Widths to 0;1.
That will have the result of displaying the BreedName field but using the BreedID field as the value of the combo box.
Use Dim BrVar As Long = Breed.SelectedItem to get the value of BreedID.

Updating the text displaid in MACROBUTTON in MS Word

I am using macrobutton in VBA to have a field whose value is calculated by accessing some other system, and at the same time, I want to be able to double-click on that field to specify some settings used to retrieve data from that other system.
The whole macro stuff works fine but I can not figure out how to change the label on the macrobutton.
Typically the macrobutton looks like this { MACROBUTTON macro_name label {some_arg}{some_arg2} }
I tried accessing selection.fields(1).code.text and even doing regexp to replace 'label' by something else but that just does not work, i.e. either I lose the args or I screw up the label.
Any advice for this issue, or perhaps a suggestion of some other type of field I could use to achieve this? I wouldn't mind using DOCVARIABLE but these can not respond to clicks and carry arguments?
You should be able to do something like this:
Sub Testit1()
Dim strText As String
Dim strLabel As String
Dim strNewLabel As String
strLabel = "Chew"
strNewLabel = "Devour"
' Replace the field code values in the first field to change the label
strText = ActiveDocument.Fields(1).Code.Text
ActiveDocument.Fields(1).Code.Text = Replace(strText, strLabel, strNewLabel)
End Sub
This will basically do a search and replace inside the field code for the macrobutton field you want to change. ActiveDocument.Fields(1).Code.Text is the part I think you are looking for.

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

Changing Column header name of ListView using vb.net code

I have a listview with several columns. I want to change the column header using code.
Please advise how to do it.
I just tested ListView1.Columns(0).Text = "changed" and it worked. This is VB.Net, winforms, VS 2010.
To change the header name, you have to use the name property
Listview1.columns(0).name = "column1Name"
But you can also assign the column name while assigning it's "text" value
Listview1.Columns.add("Column1text").name = "Column1Name"
You can then use it's name to refer to it
Listview1.columns.item(Listview1.columns("Column1Name").index).text = "Column1TextChanged"
In a List View, there is a difference between
Column Header .Name and Column Header .Text.
The .Text is displayed at the top of the List View.
The .Name is the Column Name which you can refer to in your code.
If you try to get the ListView1.Columns(0).Name in your code, it will always be "".
Unless, during the design time, in the edit column header properties,
you set Under Data, Application Settings, and Properties Binding,
the DisplayIndex Name Default Value is the .Name value.
ColumnHeader Properties