Selected item in Datagridview to display in ComboBox
source link: https://www.codesd.com/item/selected-item-in-datagridview-to-display-in-combobox.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Selected item in Datagridview to display in ComboBox
I am trying to get a selected item from datagridview to show in a combobox.
I have done
ComboBox1.Text = DataGridView1.CurrentCell.Value
However, I need it to display two fields in the combobox from the datagrid. Is there a way to do the above with a SQL query? Because I need to concat a query to display in the combobox because right now it's only displaying one field that I need. Thank you :-)
You could try doing something like this.
ComboBox1.Text = DataGridView1.SelectedRows.Item(0).Cells(0).FormattedValue + " " + DataGridView1.SelectedRows.Item(0).Cells(1).FormattedValue
ComboBox1.Text = DataGridView1.SelectedRows.Item(0).Cells(0).FormattedValue + " " + _
DataGridView1.SelectedRows.Item(0).Cells(1).FormattedValue
However if your drop down list box has an ID in the value you and you have it in the Grid, you set the
ComboBox1.Value = DataGridView1.Rows[DataGridView1.SelectedIndex].Cells["HiddenIdRow"].Text.ToString()
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK