将单选按钮添加到数据网格 [英] Adding a Radio button to a datagrid
问题描述
我想在我的数据网格中添加一个单选按钮,但我不确定该怎么做。 我看到的一些示例将它添加到表单加载中,但我使用2个组合框过滤视图。
我假设我必须将它们添加到BtnSearch子,但是我见过的大部分例子都是将它们添加到Datagridview而不是像我一样的数据表。
一旦选择了所选项目,我想将此选项与其他一些控件一起使用使用FPDF .net打印文档。
任何帮助都不胜感激。
以下是表格的代码:
Public Class frmSecond
Private connectionString As String =" Data Source = DESKTOP-S7FRNAL\SQLEXPRESS; Initial Catalog = Verses_Find; Integrated Security = True"
Public Property dt As Object
Private Sub frmSecond_Load_1(sender As Object,e As EventArgs)Handles MyBase.Load
Me.Sub_EventTableAdapter2.Fill(Me.Verses_FindDataSet21.Sub_Event)
Me.Event_TypeTableAdapter1.Fill(Me.Verses_FindDataSet11.Event_Type)
Me.VerseTableAdapter1.Fill(Me.Verses_FindDataSet2.Verse)
DataGridView2.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
Me.DataGridView2。 DefaultCellStyle.WrapMode = DataGridViewTriState.True
Me.TopMost = True
Me.WindowState = FormWindowState.Maximized
Me.VerseTableAdapter1.Fill(Me.Verses_FindDataSet2.Verse )
Dim sql As String = Nothing
Dim ds As New DataSet()
Dim stepInfo As String = String.Empty
尝试
stepInfo ="步骤:instatiate连接"
使用连接As New SqlConnection(connectionString)
stepInfo =" Step:test open connection"
connection.Open()
stepInfo =" Step:load first data"
sql ="从Event_Type中选择SID,EVENT"
使用适配器As New SqlDataAdapter(sql,connection)
adaptor.Fill(ds," Tab_Event_Type")
End using
stepInfo =" Step:load second data"
sql ="从Sub_Event中选择BID,SUBEVENT"
使用适配器As New SqlDataAdapter(sql,connection)
adaptor.Fill(ds," Tab_Sub_Event")
End using
End using
stepInfo =" Step :bind first combobox"
ComboBox3.DataSource = ds.Tables(" Tab_Event_Type")
ComboBox3.ValueMember =" SID"
ComboBox3.DisplayMember =" Event"
stepInfo ="步骤:绑定第二个组合框"
ComboBox4.DataSource = ds.Tables(" Tab_Sub_Event")
ComboBox4.ValueMember =" BID"
ComboBox4.DisplayMember =" Event_Sub"
Catch ex As Exception
MessageBox.Show($"错误:{stepInfo} {vbNewLine} {ex.ToString}")
结束尝试
End Sub
Private Sub BtnSearch_Click(sender as Object,e As EventArgs)处理BtnSearch.Click
Dim sql As String = Nothing
Dim sqlAdapter As SqlDataAdapter
Dim cboVal1 As整数
Dim cboVal2 As Integer
Dim dt As New DataTable()
cboVal1 = CInt(ComboBox3.SelectedValue)
cboVal2 = CInt(ComboBox4.SelectedValue)
使用连接为新SqlConnection(connectionString)
connection.Open()
Dim selectStatement = $"从Verse中选择Verse,其中Event = {cboVal1}和Event_Sub = {cboVal2}" ;
sqlAdapter =新的SqlDataAdapter(selectStatement,connection)
dt = New DataTable()
sqlAdapter.Fill(dt)
DataGridView2.DataSource = dt
Dim rowCount = 0
rowCount = dt.Rows.Count
TextBox1.Text = rowCount
End using
End Sub
Private Sub btnClose_Click(sender As对象,e作为EventArgs)处理btnClose.Click
关闭()
结束子
结束类
TEH
你好,
这是你要找的吗?
我是怎么做到的?使用三个DataGridViewImageColumn列。 DataGridView是通过DataTable加载的,DataTable在这种情况下包含公司名称和"假"信息。单选按钮不在DataTable中。
是的,我们可以得到结果: - )
I want to add a Radio button to my datagrid, but I am unsure how to do it. Some od the examples I have seen add it to the form load, but I filter the view by using 2 combo boxes.
I assume that I would have to add them to the BtnSearch sub, but most of the examples I have seen add them to a Datagridview and not a datatable as I have.
Once the chosen item is selected I want to use this choice along with some other controls to print a document using FPDF .net.
Any help woul be appreciated.
Here is the code for the form:
Public Class frmSecond Private connectionString As String = "Data Source=DESKTOP-S7FRNAL\SQLEXPRESS;Initial Catalog=Verses_Find;Integrated Security=True" Public Property dt As Object Private Sub frmSecond_Load_1(sender As Object, e As EventArgs) Handles MyBase.Load Me.Sub_EventTableAdapter2.Fill(Me.Verses_FindDataSet21.Sub_Event) Me.Event_TypeTableAdapter1.Fill(Me.Verses_FindDataSet11.Event_Type) Me.VerseTableAdapter1.Fill(Me.Verses_FindDataSet2.Verse) DataGridView2.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells Me.DataGridView2.DefaultCellStyle.WrapMode = DataGridViewTriState.True Me.TopMost = True Me.WindowState = FormWindowState.Maximized Me.VerseTableAdapter1.Fill(Me.Verses_FindDataSet2.Verse) Dim sql As String = Nothing Dim ds As New DataSet() Dim stepInfo As String = String.Empty Try stepInfo = "Step: instatiate connection" Using connection As New SqlConnection(connectionString) stepInfo = "Step: test open connection" connection.Open() stepInfo = "Step: load first data" sql = "Select SID, EVENT from Event_Type" Using adaptor As New SqlDataAdapter(sql, connection) adaptor.Fill(ds, "Tab_Event_Type") End Using stepInfo = "Step: load second data" sql = "Select BID, SUBEVENT from Sub_Event" Using adaptor As New SqlDataAdapter(sql, connection) adaptor.Fill(ds, "Tab_Sub_Event") End Using End Using stepInfo = "Step: bind first combobox" ComboBox3.DataSource = ds.Tables("Tab_Event_Type") ComboBox3.ValueMember = "SID" ComboBox3.DisplayMember = "Event" stepInfo = "Step: bind second combobox" ComboBox4.DataSource = ds.Tables("Tab_Sub_Event") ComboBox4.ValueMember = "BID" ComboBox4.DisplayMember = "Event_Sub" Catch ex As Exception MessageBox.Show($"Error: {stepInfo}{vbNewLine}{ex.ToString}") End Try End Sub Private Sub BtnSearch_Click(sender As Object, e As EventArgs) Handles BtnSearch.Click Dim sql As String = Nothing Dim sqlAdapter As SqlDataAdapter Dim cboVal1 As Integer Dim cboVal2 As Integer Dim dt As New DataTable() cboVal1 = CInt(ComboBox3.SelectedValue) cboVal2 = CInt(ComboBox4.SelectedValue) Using connection As New SqlConnection(connectionString) connection.Open() Dim selectStatement = $"Select Verse From Verse where Event= {cboVal1} and Event_Sub= {cboVal2}" sqlAdapter = New SqlDataAdapter(selectStatement, connection) dt = New DataTable() sqlAdapter.Fill(dt) DataGridView2.DataSource = dt Dim rowCount = 0 rowCount = dt.Rows.Count TextBox1.Text = rowCount End Using End Sub Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click Close() End Sub End Class
TEH
Hello,
Is this what you are looking for?
How did I do this? Using three DataGridViewImageColumn columns. The DataGridView is loaded via a DataTable which contains, in this case the company name and the "fake" radio buttons are not in the DataTable.
And yes we can get the results :-)
这篇关于将单选按钮添加到数据网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!