How to add and delete Columns in a DataGridView ??

Posted by M3nhaq under C# on 12/9/2011 | Points: 10 | Views : 1933 | Status : [Member] | Replies : 1
Hello All!

I am new to WinForms and not know much about daraGrudView. I want to create a dataGridView contains textItem, Combobox and Button in my winForm. The button will be use for add and delete column from daraGrudView.
Kindly share any tutorial or code to do so.

Thanks in advance.




Responses

Posted by: Hmanjarawala on: 12/9/2011 [Member] Bronze | Points: 25

Up
0
Down
Here is a logic in which i m adding text column, combobox column, button column and checkbox column in perticular datagridview row
Hope this will help you

For Each row As DataRow In source.Rows
Dim dgvNewRow As New DataGridViewRow

Dim textBoxColumn As DataGridViewTextBoxCell
Dim checkBoxColumn As DataGridViewCheckBoxCell
Dim buttonColumn As DataGridViewButtonCell

Dim ComboBoxColumn As DataGridViewComboBoxCell


textBoxColumn = New DataGridViewTextBoxCell
textBoxColumn.Value = row("AppBatchID")
dgvNewRow.Cells.Add(textBoxColumn)

textBoxColumn = New DataGridViewTextBoxCell
textBoxColumn.Value = row("AppBatchName")
dgvNewRow.Cells.Add(textBoxColumn)

textBoxColumn = New DataGridViewTextBoxCell
textBoxColumn.Value = row("AppNoOfFiles")
dgvNewRow.Cells.Add(textBoxColumn)

checkBoxColumn = New DataGridViewCheckBoxCell
checkBoxColumn.Value = row("AppIsProcessed")
dgvNewRow.Cells.Add(checkBoxColumn)

ComboBoxColumn = New DataGridViewComboBoxCell
ComboBoxColumn.DataSource = dtClient
ComboBoxColumn.DisplayMember = "appETClientName"
ComboBoxColumn.ValueMember = "appETClientID"
ComboBoxColumn.Value = row("appAllocateClientID")
dgvNewRow.Cells.Add(ComboBoxColumn)

ComboBoxColumn = New DataGridViewComboBoxCell
ComboBoxColumn.DataSource = dtStatus
ComboBoxColumn.DisplayMember = "appBatchStatusName"
ComboBoxColumn.ValueMember = "appBatchStatus"
ComboBoxColumn.Value = row("AppBatchStatus")
dgvNewRow.Cells.Add(ComboBoxColumn)

buttonColumn = New DataGridViewButtonCell
buttonColumn.Value = "Reset Batch"
dgvNewRow.Cells.Add(buttonColumn)

dgvBatchMaster.Rows.Add(dgvNewRow)
Next

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

M3nhaq, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response