Changing Column header name of ListView using vb.net code - vb.net

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

Related

MS Access Object Required Error on Combo Box Column

I have a combo box in Access named StateID. It's rowsource contains two columns one is ID which is in Column 0 and another is description which is Column 1.
I want to populate the value of the ID column by doing something like:
StateID.Column(0) = rs("ID")
I made sure that the combobox is name StateID. The rs("ID") is also returning a value but my code breaks on the line above and I get
Object Required
error.
I alos tried Me.StateID.Column(0) and StateID.Column(0).value but I still get the same error
You cannot do "something like" that because the "Column" property is Read-Only, per Microsoft Access documentation; seems like this is your problem.
I dont' know why you don't assign the record source in design mode. Any way, in the Form Load event you can do this
StateID.RowSource = "SELECT codage,nomage FROM TheTable"
Well I just tried various things and doing it this way works:
With StateID
.ColumnCount = 2
.Value = rs("ID")
End With

Add header row to listbox

I am using listboxes to display data in userforms in word. However I am not able to set header captions or figure out how to make it possible to click on the header to sort by that column.
GUI.Search_ListBox.Clear
GUI.Search_ListBox.ColumnCount = 5 ' Columns
GUI.Search_ListBox.ColumnWidths = "120;80;70;120;300"
GUI.Search_ListBox.ColumnHeads = True
'GUI.Search_ListBox.RowSource = "Hello;gkjfl;hsjgh;hdfjhgkj;fdjghjkdf" 'here it fails!!!
With VBA, simply set the ListBox.ColumnHeads Property to True.
Alternatively, you can also change the setting in the ActiveX control's Properties dialog:
If the button is disabled on the ribbon, you'll have to enter first.
More Information:
ListBox.ColumnHeads Property (Access)
EDIT:
You need to specify the headings in the rowsource:
Column headings are enabled and either field captions, field names, or the first row of data items are used as column headings.
I just create another list box and place it right above the primary listbox, make it flat etc. Then use the header row as the row source. That way any calculations made in the header row shows on the form as well.

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.

Setting field of Access table using VBA from form

I'm trying to set a value of a field from a subroutine which I'm calling from an event handler. I'm simply doing width = 5
However, the field value isn't changed. However I can do height = 5 and the field value is set as expected. The field value for width remains unchanged at 12186.
I've tried changing the field name to image_width to no avail.
The form has neither controls height nor width.
What am I doing wrong / why is this one field not changing. I've tried deleting the field and recreating, and I don't see anything on this field that limits the setting of data.
Every form has an inbuilt property .Width so you can't use that for a field name.
A form doesn't have .Height, since this is a property of the form sections.
image_width shold work, though. Are you sure you edited all relevant settings?
i.e. Table field name, form field Name, form field Controlsource, VBA code?

Bold a certain value of a specified column in a specific grid - 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)