datagridview combo box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, has anyone probably solved the following issue:
I want to create a datagridview with a combobox displaying value from a
datatable.
This work fine as long as I 'hardcode' the necessary properties into the
datagridcolumn. Is there any way to get the property information from a
database which sort of "configures" the datagridcolumn.
ie I do a:
Dim newcol As New DataGridViewComboBoxColumn
countrytableadapter.Fill(countrytable)
newcol.DataSource = countrytable
newcol.DisplayMember = "country_name"
newcol.HeaderText = "New col"
newcol.ValueMember = "country_code"
newcol.DisplayIndex = 0
newcol.DataPropertyName = "ccy_country"
dg.Columns.Add(newcol)

all except lines 2 and 3 can be put in an sql table, but how would a make a
proper reference to object "countrytable" to instruct the grid that I want to
read from that datatable?
Any help is highly appreciated.

Thanks
 
ctk_at said:
Hi, has anyone probably solved the following issue:
I want to create a datagridview with a combobox displaying value from a
datatable.
This work fine as long as I 'hardcode' the necessary properties into the
datagridcolumn. Is there any way to get the property information from a
database which sort of "configures" the datagridcolumn.
ie I do a:
Dim newcol As New DataGridViewComboBoxColumn
countrytableadapter.Fill(countrytable)
newcol.DataSource = countrytable
newcol.DisplayMember = "country_name"
newcol.HeaderText = "New col"
newcol.ValueMember = "country_code"
newcol.DisplayIndex = 0
newcol.DataPropertyName = "ccy_country"
dg.Columns.Add(newcol)

all except lines 2 and 3 can be put in an sql table, but how would a make a
proper reference to object "countrytable" to instruct the grid that I want to
read from that datatable?
Any help is highly appreciated.

Thanks

I'm a bit confused on your question. Aren't you always going to fill it
from some table?

Dim T as DataTable
countrytableadapter.Fill(T)
newcol.DataSource = T

What is the issue with hardcoding that?
 
The issue is that my app has many datatables which are presented via a DGV,
which I did not programm each individually but let .net populate the DGV
columns from the respectiv table for me.
(ie dgv.datasource = dataset .........)
This generates standard dgv columns with colheaders from the datatable fields.

I a second run through the dgv I change the col headers, color and so on and
on some fields I want to restrict the possible input to a list of values that
come from an other table. In other word each column of each table get
properties set which again do come from a table. But again instead of
hardcoding these restrictions in the application I would want to read the
setting from my columnproperty table.

The problem is that I very well can say ie
dg.column(0).width = valueofsomefieldinmydatabase
or
dg.column(0).columnheader = somedatafieldfrommycolumnsdatatable
because one expect integer the other string datatype

but I can not say
dim newcol as new datagridviewcombobox
newcol.datasource = valueofsomefieldinmydatabase

because newcol.datasource expects an object of type datatable which is not
something that I can store in an sql table. The question is if I can convert
valueofsomefieldinmydatabase into a reference to a datatable that was
already defined an filled in the application.

I not sure if these is clear enough.

Thanks,
 
Back
Top