I have a windows app that has a Datagrid where a user can input a printer Id, Printer Desc, and select from installed local printer. Currently once you add to the datagrid their is no way of deleting your input, therefore I would like to add a delete button in a column and when clicked it would delete that row. If somebody could help me out or point me in the right diection that would be great. Thanks
VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] pop_dgPrinters()
[/SIZE][SIZE=2][COLOR=#008000]' populate the dgPrinters datagrid including dropdown
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] objPrintersCM [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] CurrencyManager
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] objPrintersTableStyle [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataGridTableStyle
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] objGridCol [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataGridColumnStyle
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] intAvgCharWidth [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] rowPrintersLookup [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataRow
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] tblPrintersLookup [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataTable = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataTable("PrintersLookup")
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] gridTableStyle [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataGridTableStyle
[/SIZE][SIZE=2][COLOR=#008000]'
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'create an instance of the datagridstyle object
[/COLOR][/SIZE][SIZE=2]gridTableStyle = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataGridTableStyle()
[/SIZE][SIZE=2][COLOR=#008000]'
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' calculate the average character display width
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE][SIZE=2] Graphics.FromHwnd([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Handle).MeasureString(Text:="ABCDEFGHIJKLMNOPQRSTUVWXYZ" _
, Font:=[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Font)
intAvgCharWidth = [/SIZE][SIZE=2][COLOR=#0000ff]CInt[/COLOR][/SIZE][SIZE=2](.Width / 26.0!)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]With
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' create the printerslookup table
[/COLOR][/SIZE][SIZE=2]tblPrintersLookup.TableName = "PrintersLookup"
tblPrintersLookup.Columns.Add("PrinterName", Type.GetType("System.String"))
[/SIZE][SIZE=2][COLOR=#008000]' add the values to the printers lookup table
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] pkInstalledPrinters [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] pkInstalledPrinters [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] System.Drawing.Printing.PrinterSettings.InstalledPrinters
rowPrintersLookup = tblPrintersLookup.NewRow
rowPrintersLookup.Item("PrinterName") = pkInstalledPrinters
tblPrintersLookup.Rows.Add(rowPrintersLookup)
[/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' get handle to the currency manager for the printers table
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' use to build grid display
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE][SIZE=2] dsStationSettings.Tables
objPrintersCM = [/SIZE][SIZE=2][COLOR=#0000ff]CType[/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].BindingContext(.Item(Name:="Printers")), CurrencyManager)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]With
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' set up the grid display
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE][SIZE=2] gridTableStyle
.MappingName = "Printers"
[/SIZE][SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE][SIZE=2] .GridColumnStyles
[/SIZE][SIZE=2][COLOR=#008000]' add column for printer id
[/COLOR][/SIZE][SIZE=2].Add(column:=[/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataGridTextBoxColumn(objPrintersCM. _
GetItemProperties.Item(Name:="PrinterID")))
[/SIZE][SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE][SIZE=2] .Item(index:=0)
.MappingName = "PrinterID"
.HeaderText = "Printer ID"
.Alignment = HorizontalAlignment.Left
.Width = intAvgCharWidth * 10
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]With
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' add column for printer name with dropdown
[/COLOR][/SIZE][SIZE=2].Add(column:=[/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataGridComboBoxColumnStyle(datasource:=tblPrintersLookup, _
DisplayMember:=0, ValueMember:=0))
[/SIZE][SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE][SIZE=2] .Item(index:=1)
.MappingName = "PrinterName"
.HeaderText = "Printer Name"
.Alignment = HorizontalAlignment.Left
.Width = intAvgCharWidth * 20
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]With
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' add column for printer description as textbox
[/COLOR][/SIZE][SIZE=2].Add(column:=[/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataGridTextBoxColumn(objPrintersCM. _
GetItemProperties.Item(Name:="PrinterDesc")))
[/SIZE][SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE][SIZE=2] .Item(index:=2)
.MappingName = "PrinterDesc"
.HeaderText = "Printer Description"
.Alignment = HorizontalAlignment.Left
.Width = intAvgCharWidth * 20
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]With
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]With
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' wire up the grid control
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE][SIZE=2] dgPrinters
.CaptionText = "Printers"
.DataSource = tblPrinters
.TableStyles.Add(table:=gridTableStyle)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]EndWith
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]