John
John

Reputation: 785

DataGrid Column id's

Quick one chaps,

If I have a datagridview control, lets call it 'tasklist'.

When I populate it, there are 3 columns, 'id', 'tasktitle' and 'owner'. I dont want to show the 'id' on screen so I simply do: tasklist.Columns(0).Visible = False

Thats all good and the id column is not visible.

Does this then mean in terms of referencing the column numbers that 1 becomes 0 and 2 becomes 1?

or does the non-visable 'id' column retain the 0 id and 1 and 2 also stay the same?

Thanks!

Upvotes: 0

Views: 541

Answers (1)

Fabio
Fabio

Reputation: 32455

This is not answer to question - just "better practice" for not using indexes(hard-coding).

Create predefined columns through designer.
Give a name for every column(for example: task_id, task_title and task_owner)

Then through designer you can set Visible property task_id.Visible = false(or in code)

Then in code(Load event) add mydatagridview.AutoGenerateColumns = false - this will prevent datagridview generate columns

After this you can use your column without doubt about indexes

mydatagridview.Rows(0).Cells(task_owner.Name).Value = 'testowner'

Upvotes: 2

Related Questions