how to show combobox in datagrid in vb.net - view

I have this query below and I want to show items that sold depending on sales_id without repeat the old ids. And another question how to make a combo box data grid view:
Private Sub filldatagrid()
Dim myTableName As String
myTableName = txtid.Text
winclass.filldatagrid(DataGridView1, "select inventory.inv_name,sales_data.sales_id,sales_data.quantity,sales_data.sum_total from sales_data,inventory where sales_data.inv_id=inventory.inv_id ")
DataGridView1.Columns(0).HeaderText = "ID"
DataGridView1.Columns(0).Visible = True
DataGridView1.Columns(1).HeaderText = "name"
DataGridView1.Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
End Sub

Related

How do i set the celltype for a datagrid column?

I am adding a new column to a datagrid to store a row total of qty*Cost
When I try to add the column I get an exception saying
System.InvalidOperationException: 'Column cannot be added because its CellType property is null.'
I've tried to set the cell type but I can't get the type right
Dim dt As DataTable = Me.DsOppQuoteDetail.tblOppQuoteDetail
Dim dr As DataRow
Dim dc As New DataGridViewColumn
With dc
.HeaderText = "Item Total"
.Name = "UnitTotal"
.CellType = DataGridTextBox
End With
DGV_OppQuoteDetail.Columns.Insert(6, dc)
Setting the CellType to DataGridTextBox produces an error
If I change the the column to:
Dim dc As New DataGridTextBoxColumn
With dc
.HeaderText = "Item Total"
End With
DGV_OppQuoteDetail.Columns.Insert(6, dc)
then I can't insert it because it's the wrong type for the DataGrid.Insert command
Dim dc As New DataGridViewTextBoxColumn
dc.HeaderText = "SomeText"
dc.Name = "colWhateverName"
DGV_OppQuoteDetail.Columns.Add(dc)
Try this and let me know. Only slightly different in terms of wording. Also from your code snippet it seems fine but make sure you don't add any rows before adding a column.

DataTable: create rows dynamically according to the number of checkboxes selected in the checkbox List

I am trying to create a DataTable the number of rows of which needs to be created automatically according to the number of checkboxes checked in my checkbox list:
Private Function GetRoomTypeIds() As DataTable
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn(1) {New DataColumn("Id", GetType(Integer)), New DataColumn("RoomTypeId", GetType(Integer))})
dt.Rows.Add(txtId1.Text, chkRoomTypes.SelectedValue)
Return dt
End Function
I would need to add something like:
"For Each Checkbox checked in my checkbox list generate the corresponding number of rows."
Thanks
I solved as per below code:
Private Function GetRoomTypeIds() As DataTable
Dim selectedItems = From s In chkRoomTypes.Items.Cast(Of ListItem)
Where s.Selected
Select s
Dim itemTable As DataTable
itemTable = New DataTable("SelectedItems")
Dim column1 As DataColumn = New DataColumn("RateTypeId")
column1.DataType = System.Type.GetType("System.Int32")
Dim column2 As DataColumn = New DataColumn("RoomTypeId")
column2.DataType = System.Type.GetType("System.Int32")
itemTable.Columns.Add(column1)
itemTable.Columns.Add(column2)
Dim Row As DataRow
For Each item In selectedItems
Row = itemTable.NewRow()
Row("RateTypeId") = Convert.ToInt32(txtId1.Text)
Row("RoomTypeId") = item.Value
itemTable.Rows.Add(Row)
Next
Return itemTable
End Function
Thanks

MS Access underline text in a Table

I have long Text field in a table in MS ACCESS. I need to underline it for specific text in a field. I tried to change Text format to Rich Text in the design view , but I am getting:
Error : Operation is not supported for this type of Object
In the table I have 320 rows. I need to Underline for N.J.S.A. only in the long text.
Please help me regarding this. Thanks in Advance
Well... you have to get that field property changed from plain text to rich text for this to work and design view should handle this. If not try the below code.
Public Sub TestUnderline()
Dim db As DAO.Database
Dim tbl As DAO.TableDef
Dim fld As Field
Dim rst As DAO.Recordset
Dim strSQL As String
Dim strString As String
Set db = CurrentDb
Set tbl = db.TableDefs("Table1") 'Change to your table name
Set fld = tbl.Fields("TestField") 'Change to your field name
With fld.Properties("TextFormat")
If .Value = acTextFormatPlain Then
.Value = acTextFormatHTMLRichText
End If
End With
strSQL = "SELECT TestField " & _ 'Change to your Field name
"FROM Table1;" 'Change to your table name
Set rst = db.OpenRecordset(strSQL)
Do While Not rst.EOF
If InStr(1, rst![TestField], "N.J.S.A") Then 'Change to your field name
strString = Replace(rst![TestField], "N.J.S.A", "<u>N.J.S.A</u>") 'Change to your field name
rst.Edit
rst![TestField] = strString 'Change to your field name
rst.Update
End If
rst.MoveNext
Loop
EndCode:
If Not rst Is Nothing Then
rst.Close
Set rst = Nothing
End If
If Not tbl Is Nothing Then
Set tbl = Nothing
End If
If Not db Is Nothing Then
Set db = Nothing
End If
End Sub
Credit given to:
How to convert a text field in an Access table to a rich text memo using VBA
and:
http://www.tek-tips.com/viewthread.cfm?qid=1538917

Show/Hide ColumnGroups with a mix of hidden and displayed columns

I've got a RadGrid with programmatically generated columns, including a variable number of column groups. Each of the column groups contains four columns, two that are displayed and two that are not.
Above the RadGrid I have a series of checkboxes, one for each column group. The goal is to have the user check or uncheck the boxes depending on what columns they wish to see. Currently I am setting the columns' Display properties when a checkbox's checked value is changed by using radgrid.Columns.FindByUniqueName("columnName").Display. However the column group itself cannot be accessed this way. As it is, the column groups disappear when all their child columns disappear, but they do not reappear when their child columns are displayed, causing the headers to become misaligned.
Relevant code:
'Defining the grid
Dim radgrid As RadGrid
radgrid = New RadGrid()
Dim i as Integer = 0
For Each r As DataRow In subTable.Rows
Dim colGroup As GridColumnGroup = New GridGroupColumn()
radgrid.MasterTableView.ColumnGroups.Add(colGroup)
colGroup.HeaderText = r.Item("Name")
colGroup.Name = "colGroup" & i
Dim colID As GridBoundColumn = New GridBoundColumn()
radgrid.MasterTableView.Columns.Add(colID)
colID.ColumnGroupName = "colGroup" & i
colID.DataField = "id" & i
colID.HeaderText = "ID"
colID.UniqueName = "id" & i
colID.Display = False
Dim colScore As GridBoundColumn = New GridBoundColumn()
radgrid.MasterTableView.Columns.Add(colScore)
colScore.ColumnGroupName = "colGroup" & i
colScore.DataField = "score" & i
colScore.HeaderText = "Score"
colScore.UniqueName = "score" & i
i += 1
Next
'Checkbox CheckedChanged sub
If selectedButton.Checked = True Then
radgrid.Columns.FindByUniqueName("colScore" & selectedButton.Value.ToString()).Display = True
Else
radgrid.Columns.FindByUniqueName("colScore" & selectedButton.Value.ToString()).Display = False
End If
Ideally I'd like to do something like radgrid.MasterTableView.ColumnGroups.FindGroupByName("colGroup" & selectedButton.Value.ToString()).Display = False but there is no Display property for that and the Visible property is ReadOnly. I've also tried re-setting the ColumnGroupName of the columns after setting them to display, but that also does not work.
I'm guessing the fact that I have hidden columns is what's making this more complicated than it should be, but is there a way to get this to work with hidden columns?
The solution actually turned up when I was working on a somewhat unrelated issue.
Calling radgrid.Rebind() after changing the value of the Display property causes the group column headers to disappear and reappear as desired.
Protected Sub button_CheckChanged()
If selectedButton.Checked = True Then
radgrid.Columns.FindByUniqueName("colScore" & selectedButton.Value.ToString()).Display = True
Else
radgrid.Columns.FindByUniqueName("colScore" & selectedButton.Value.ToString()).Display = False
End If
radgrid.Rebind()
End Sub

How to insert a data field into an empty table

I am making a front-end application in VB. The back-end is Oracle. I want an autogenerated ID on the click of a "New" button. It works well if data is present in the table, but shows an error if the table is empty. What do I need to insert so that it works when I am using the application for the first time? My button code is as follows:
Private Sub cmd_new_Click()
Call txt_clear
txt_name.Enabled = True
Set rsCat = New ADODB.Recordset
rsCat.Open "Category", conn, adOpenDynamic, adLockPessimistic
If rsCat.EOF = rscat.BOF Then
tempId = 1000
Else
rsCat.MoveLast
tempId = rsCat.Fields("Category_Id") + 1
End If
txt_Id = tempId
cmd_Save.Enabled = True
cmd_new = False
End Sub
check rscat.RecordCount=-1
Basically, change
If rsCat.EOF = rscat.BOF Then
to
If rsCat.RecordCount=-1 Then

Resources