Hi All,
I've got a DataGridView with six columns. Three of these columns are actually comboboxes (i.e. each row in the datagridview is a combobox) aka DataGridViewComboBoxColumn. I have successfully populated each combobox with the collection I want from a dataset.
On form load, I want to populate the entire datagridview with another dataset. I'd like to have the combobox's text value to be equal to that of the dataset. So for example I have a "Category" column with different possible values. When the dataset is populated, the Category column should select the category for that row based on what is coming from the database/dataset. I know if the combobox was on the form directly it would just be combobox.text (or selectedtext, I never remember which). I'm guessing part of the problem is I need to reference the combobox for each specific row.
After talking to a friend, he said it would have to happen in the rowdatabound event, which I don't seem to see and based on what I'm reading online is an ASP event not available in Windows Forms.
I've spent a ton of time trying different things online, and nothing has worked so far. Did a search here on the forum and also didn't find a solution.
Any help would be very appreciated.
I've got a DataGridView with six columns. Three of these columns are actually comboboxes (i.e. each row in the datagridview is a combobox) aka DataGridViewComboBoxColumn. I have successfully populated each combobox with the collection I want from a dataset.
On form load, I want to populate the entire datagridview with another dataset. I'd like to have the combobox's text value to be equal to that of the dataset. So for example I have a "Category" column with different possible values. When the dataset is populated, the Category column should select the category for that row based on what is coming from the database/dataset. I know if the combobox was on the form directly it would just be combobox.text (or selectedtext, I never remember which). I'm guessing part of the problem is I need to reference the combobox for each specific row.
After talking to a friend, he said it would have to happen in the rowdatabound event, which I don't seem to see and based on what I'm reading online is an ASP event not available in Windows Forms.
I've spent a ton of time trying different things online, and nothing has worked so far. Did a search here on the forum and also didn't find a solution.
Any help would be very appreciated.
VB.NET:
sqlAdvising = "SELECT A.Category, B.Course_Nbr,A.Class_Date, A.Evaluation, A.Notes,A.Curriculum_ID" & vbCrLf & _
", CASE WHEN Category = 'Pre-Core' THEN 1" & vbCrLf & _
"WHEN CATEGORY = 'Core' THEN 2" & vbCrLf & _
"WHEN CATEGORY = 'Concentration' THEN 3" & vbCrLf & _
"WHEN CATEGORY = 'Elective' THEN 4" & vbCrLf & _
"END AS SORT " & vbCrLf & _
", CASE WHEN CLASS_DATE IS NOT NULL THEN 1" & vbCrLf & _
"ELSE 2" & vbCrLf & _
"END AS SORT_TWO" & vbCrLf & _
"FROM dbo.STUDENT_CURRICULUM A" & vbCrLf & _
"INNER JOIN dbo.Course B ON A.Course_ID = B.Course_ID" & vbCrLf & _
"INNER JOIN dbo.Matriculation C on A.Matriculation_ID = C.Matriculation_ID" & vbCrLf & _
"WHERE( C.Person_ID = 1)" & vbCrLf & _
"ORDER BY SORT,SORT_TWO, B.Course_Nbr"
Dim sqlCategory As String = "SELECT RTRIM(Pam_Val) as Pam_Val FROM dbo.Paramater_Values WHERE Key_Value = 'frmDegreeCourseCat' ORDER BY 1"
ds = _DBConnector.executeSelect(sqlAdvising)
dtAdvising = ds.Tables(0)
dgvAdvising.ForeColor = Color.Black
dvAdvising = dtAdvising.DefaultView
AdvisingBindingSource.DataSource = dtAdvising
dgvAdvising.DataSource = AdvisingBindingSource
ds2 = _DBConnector.executeSelect(sqlCategory)
For Each dr2 In ds2.Tables(0).Rows
colDDLCoreCategory.Items.Add(dr2(0).ToString.Trim)
colDDLCoreCategory.Selected = True
Next