|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
datagridview Combobox column[vb2008] I need help with the following, I have a grid that i have put on there 2 textbox's and a combobox column which works ok. When i then add the data by using the following code below, it works, my problem is with the combobox "YesNo" it put the complete contents of the datatable into the combobox for each row. My question is how can i limit the drop down to 1 yes and 1 no. But at the same time display the correct value according to the datatable? Many Thanks Simon DataGridView1.Columns(0).Visible = False DataGridView1.Columns(1).Visible = False DataGridView1.Columns(2).Visible = False DataGridView1.Columns(3).Visible = False DataGridView1.Columns(4).Visible = False 'the questionno Dim QNo As New DataGridViewTextBoxColumn QNo.HeaderText = "Question No." QNo.DataPropertyName = "SortNo" Me.DataGridView1.Columns.Add(QNo) 'the question textbox in the grid Dim xy As New DataGridViewTextBoxColumn xy.HeaderText = "Question" xy.DataPropertyName = "shortDescription" Me.DataGridView1.Columns.Add(xy) 'drop down list on grid 'Dim xx As New DataGridViewComboBoxColumn 'xx.DataPropertyName = "defaultanswerYN" 'xx.Name = "YesNo" 'xx.Items.Add("Yes") 'xx.Items.Add("No") 'Me.DataGridView1.Columns.Add(xx) Dim YesNo As New DataGridViewComboBoxColumn With YesNo ..DataPropertyName = "yesno" ..HeaderText = "Question Answer" ..DataSource = dt ..ValueMember = "yesno" ..DisplayMember = "yesNo" End With DataGridView1.Columns.Add(YesNo) 'the Answer Question Dim yx As New DataGridViewTextBoxColumn yx.HeaderText = "Answer" yx.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells yx.DataPropertyName = "SOFTemplateText" Me.DataGridView1.Columns.Add(yx) 'the view button ' Add a button column. Dim buttonColumn As New DataGridViewButtonColumn() buttonColumn.HeaderText = "Requests" buttonColumn.Text = "Requests" buttonColumn.UseColumnTextForButtonValue = True buttonColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells buttonColumn.FlatStyle = FlatStyle.Standard DataGridView1.Columns.Add(buttonColumn) Simon,
Try to avoid Yes No dropdowns, it is mostly a lot of work (you need to create a usercontrol), while everybody understands a checkbox which is easy to do. Cor Show quoteHide quote "Simon Whale" <simon@nospam.com> wrote in message news:eIMSDWW1KHA.3412@TK2MSFTNGP05.phx.gbl... > Hi all, > > [vb2008] > > I need help with the following, I have a grid that i have put on there 2 > textbox's and a combobox column which works ok. > > When i then add the data by using the following code below, it works, my > problem is with the combobox "YesNo" it put the complete contents of the > datatable into the combobox for each row. My question is how can i limit > the drop down to 1 yes and 1 no. But at the same time display the correct > value according to the datatable? > > Many Thanks > Simon > > DataGridView1.Columns(0).Visible = False > > DataGridView1.Columns(1).Visible = False > > DataGridView1.Columns(2).Visible = False > > DataGridView1.Columns(3).Visible = False > > DataGridView1.Columns(4).Visible = False > > 'the questionno > > Dim QNo As New DataGridViewTextBoxColumn > > QNo.HeaderText = "Question No." > > QNo.DataPropertyName = "SortNo" > > Me.DataGridView1.Columns.Add(QNo) > > 'the question textbox in the grid > > Dim xy As New DataGridViewTextBoxColumn > > xy.HeaderText = "Question" > > xy.DataPropertyName = "shortDescription" > > Me.DataGridView1.Columns.Add(xy) > > 'drop down list on grid > > 'Dim xx As New DataGridViewComboBoxColumn > > 'xx.DataPropertyName = "defaultanswerYN" > > 'xx.Name = "YesNo" > > 'xx.Items.Add("Yes") > > 'xx.Items.Add("No") > > 'Me.DataGridView1.Columns.Add(xx) > > Dim YesNo As New DataGridViewComboBoxColumn > > With YesNo > > .DataPropertyName = "yesno" > > .HeaderText = "Question Answer" > > .DataSource = dt > > .ValueMember = "yesno" > > .DisplayMember = "yesNo" > > End With > > DataGridView1.Columns.Add(YesNo) > > 'the Answer Question > > Dim yx As New DataGridViewTextBoxColumn > > yx.HeaderText = "Answer" > > yx.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells > > yx.DataPropertyName = "SOFTemplateText" > > Me.DataGridView1.Columns.Add(yx) > > 'the view button > > ' Add a button column. > > Dim buttonColumn As New DataGridViewButtonColumn() > > buttonColumn.HeaderText = "Requests" > > buttonColumn.Text = "Requests" > > buttonColumn.UseColumnTextForButtonValue = True > > buttonColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells > > buttonColumn.FlatStyle = FlatStyle.Standard > > DataGridView1.Columns.Add(buttonColumn) > > I can't avoid the yes no dropdowns as its a business requirement for an
insurance back office. Show quoteHide quote "Cor Ligthert[MVP]" <Notmyfirstn***@planet.nl> wrote in message news:%23PvB2eW1KHA.5972@TK2MSFTNGP06.phx.gbl... > Simon, > > Try to avoid Yes No dropdowns, it is mostly a lot of work (you need to > create a usercontrol), while everybody understands a checkbox which is > easy to do. > > Cor > > "Simon Whale" <simon@nospam.com> wrote in message > news:eIMSDWW1KHA.3412@TK2MSFTNGP05.phx.gbl... >> Hi all, >> >> [vb2008] >> >> I need help with the following, I have a grid that i have put on there 2 >> textbox's and a combobox column which works ok. >> >> When i then add the data by using the following code below, it works, my >> problem is with the combobox "YesNo" it put the complete contents of the >> datatable into the combobox for each row. My question is how can i limit >> the drop down to 1 yes and 1 no. But at the same time display the >> correct value according to the datatable? >> >> Many Thanks >> Simon >> >> DataGridView1.Columns(0).Visible = False >> >> DataGridView1.Columns(1).Visible = False >> >> DataGridView1.Columns(2).Visible = False >> >> DataGridView1.Columns(3).Visible = False >> >> DataGridView1.Columns(4).Visible = False >> >> 'the questionno >> >> Dim QNo As New DataGridViewTextBoxColumn >> >> QNo.HeaderText = "Question No." >> >> QNo.DataPropertyName = "SortNo" >> >> Me.DataGridView1.Columns.Add(QNo) >> >> 'the question textbox in the grid >> >> Dim xy As New DataGridViewTextBoxColumn >> >> xy.HeaderText = "Question" >> >> xy.DataPropertyName = "shortDescription" >> >> Me.DataGridView1.Columns.Add(xy) >> >> 'drop down list on grid >> >> 'Dim xx As New DataGridViewComboBoxColumn >> >> 'xx.DataPropertyName = "defaultanswerYN" >> >> 'xx.Name = "YesNo" >> >> 'xx.Items.Add("Yes") >> >> 'xx.Items.Add("No") >> >> 'Me.DataGridView1.Columns.Add(xx) >> >> Dim YesNo As New DataGridViewComboBoxColumn >> >> With YesNo >> >> .DataPropertyName = "yesno" >> >> .HeaderText = "Question Answer" >> >> .DataSource = dt >> >> .ValueMember = "yesno" >> >> .DisplayMember = "yesNo" >> >> End With >> >> DataGridView1.Columns.Add(YesNo) >> >> 'the Answer Question >> >> Dim yx As New DataGridViewTextBoxColumn >> >> yx.HeaderText = "Answer" >> >> yx.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells >> >> yx.DataPropertyName = "SOFTemplateText" >> >> Me.DataGridView1.Columns.Add(yx) >> >> 'the view button >> >> ' Add a button column. >> >> Dim buttonColumn As New DataGridViewButtonColumn() >> >> buttonColumn.HeaderText = "Requests" >> >> buttonColumn.Text = "Requests" >> >> buttonColumn.UseColumnTextForButtonValue = True >> >> buttonColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells >> >> buttonColumn.FlatStyle = FlatStyle.Standard >> >> DataGridView1.Columns.Add(buttonColumn) >> >> "Simon Whale" <simon@nospam.com> a écrit dans le message de groupe de discussion : eIMSDWW1KHA.3***@TK2MSFTNGP05.phx.gbl...> Hi all, Hello,> When i then add the data by using the following code below, it works, It seems that you populate your combo with the same data as your > my problem is with the combobox "YesNo" it put the complete contents > of the datatable into the combobox for each row. My question is how > can i limit the drop down to 1 yes and 1 no. But at the same time > display the correct value according to the datatable? > With YesNo > .DataPropertyName = "yesno" > .HeaderText = "Question Answer" > .DataSource = dt DataGridView (?) Just fill your combo with Yes and No and don't bind its content. -- Fred fole***@free.fr
Adding/copying Worksheet to Excel
Programmatically add Sub Menus to a ContextMenuStrip HTML report in vb.net master - detail architecture for dataTable. textBox databinding. Sorry for reposting - can not figure out... Reading filenames into listbox Object disposal guidance needed Trouble With Timer Red TransparencyKey Not Working on Non Development Computer |
|||||||||||||||||||||||