0
votes

question may need rewording, but here is the issue, and code I am using is posted below

some background so as to understand I have a datatable bound to a datagridview with a column name column names in the code I will only show a portion of column names to save space, this section works but its needed to show issues

 DataGridView3.DataSource = fieldDT
        DataGridView3.AutoGenerateColumns = True
        fieldDT.Columns.Add("Column Name", System.Type.GetType("System.String"))
        DataGridView3.Columns(0).Width = 123
        fieldDT.Columns.Add("Field", System.Type.GetType("System.String"))
        DataGridView3.Columns(1).Width = 86
        'columns 2 through 12 are here
        fieldDT.Columns.Add("Format", System.Type.GetType("System.String"))
        DataGridView3.Columns(13).Width = 45
        fieldDT.Columns.Add(" ", System.Type.GetType("System.String"))
        DataGridView3.Columns(14).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill

I also have a combobox that I want populated with the column name in the above datatable code to bind shown next

ComboBox10.DataSource = fieldDT
        ComboBox10.DisplayMember = "Column Name"
        ComboBox10.ValueMember = "Column Name"

the combobox populates correctly with all the columnnames in the datatable

now is where the issue that I need a way to fix arises,

if I select a row in the datagridview it is changing the displayed value in the combobox, and if I select a different value in the combobox it changes the selected row in the datagridview my feeling this is by default design but hoping it can be changed

although the combobox needs that column list and needs to be upto date if someone adds another row to the datagridview I don't want them to bind in the way they change each other.

the combo box is used for another purpose that it needs to select one of the available column names

1
very hard to follow with no sentence breaks(.), but it sounds like you dont want the CBO bound to the same datasource. Instead, respond to SelectItem/Index changed. Also, rather than binding the DGV to a table, bind it to a DataView. When the CBO changes, you just have to create or change the view - Ňɏssa Pøngjǣrdenlarp
I added a dataview based of the fieldDT datatable then bound the combo box to that dataview and now works like I want - Robert Allen
Instead of adding a comment, which we can't see without opening the question, please add an answer to show what you did. That tells us that you no longer need help and it also may help someone else. - jmcilhinney

1 Answers

1
votes

I made the suggested change and now works as intended thanks

Dim DV_fields As DataView = fieldDT.DefaultView
ComboBox10.DataSource = DV_fields
ComboBox10.DisplayMember = "Column Name"
ComboBox10.ValueMember = "Column Name"
ComboBox10.Text = ""