-
Feb 14th, 2025, 01:45 PM
#1
Thread Starter
Hyperactive Member
DataGridView DataSource
I have row set in my IDE. At run time I want to load a set number of new rows. 25 below but that might become a variable.
Each row as a ComboBox. How can I set the row's datasource to a list at runtime/
Code:
For i As Integer = 0 To 25 - 1
Dim DGVR = New DataGridViewRow()
gameDataGrid.Rows.Add()
Next
-
Feb 15th, 2025, 12:30 AM
#2
Re: DataGridView DataSource
Firstly, you don't need a loop. The .Rows.Add method you're calling allows you to specify a number of rows to add, so you can add them all in one call.
As for the data source for the drop-down list, you can set the DisplayMember, ValueMember and DataSource properties of the column exactly as you would for a regular ComboBox. Those property values will then be propagated to every cell in the column and any editing contro9ls that are embedded in those cells. If you need different values for different rows, you can set those same properties on individual cells explicitly, which will then be propagated to any editing controls. To access row, simply index or enumerate the Rows collection. To access a cell within a row, index its Cells collection, or you can index the grid itself by column and row.
Note that, when you get a cell, you'll only get a DataGridViewCell reference. You'll need to cast as type DataGridViewComboBoxCell in order to access type-specific properties. The same goes for the column if you index the Columns collection, i.e. DataGridViewColumn to DataGridViewComboBoxColumn, although you will have a filed of the correct type if you created the columns in the designer.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|