datagridview

WinForms DataGridView - databind to an object with a list property (variable number of columns)

夙愿已清 提交于 2020-01-18 22:40:50
问题 I have a .NET class I'd like to show in a DataGridView, and the default databinding - setting the DGV's DataSource to the object - produces 90% of my requirements (i.e. it's outputting the public properties correctly and I can add sorting easily). However, one of the properties I need to bind is a List which contains data which needs to be in separate columns after the other databound items. I'm stuck on how best to implement this. My class looks something like this: public class BookDetails

WinForms DataGridView - databind to an object with a list property (variable number of columns)

故事扮演 提交于 2020-01-18 22:38:45
问题 I have a .NET class I'd like to show in a DataGridView, and the default databinding - setting the DGV's DataSource to the object - produces 90% of my requirements (i.e. it's outputting the public properties correctly and I can add sorting easily). However, one of the properties I need to bind is a List which contains data which needs to be in separate columns after the other databound items. I'm stuck on how best to implement this. My class looks something like this: public class BookDetails

Cannot implicitly convert type 'int' to 'string' ? c#4 [closed]

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-17 23:21:46
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . while running the given below code, getting an error. I have to perform delete operation through gridview. code: protected void gvEdit_RowDeleting(object sender, GridViewDeleteEventArgs e) { string Emp_ID = gvEdit.DataKeys[e.RowIndex].Value.ToString(); int EId = Convert.ToInt32(Emp_ID); // error

DataGridViewButtonCell button color change on click

*爱你&永不变心* 提交于 2020-01-17 14:17:45
问题 I have a DataGridViewRow that I add to a DataGridView "table" programatically. I want one of the cells to be a DataGridViewButtonCell so I can click on it. (I realize I can have a handler on the datagridview for on_click but I'd like to keep this way for simplicity of code). I want to be able to set the forecolor/backcolor of a DataGridViewButtonCell. DataGridViewRow dgvRow = new DataGridViewRow(); dgvRow = (DataGridViewRow)dgv.Rows[0].Clone(); dgvRow.Cells[0].Value = filename; dgvRow.Cells[0

DataGridViewButtonCell button color change on click

倖福魔咒の 提交于 2020-01-17 14:17:21
问题 I have a DataGridViewRow that I add to a DataGridView "table" programatically. I want one of the cells to be a DataGridViewButtonCell so I can click on it. (I realize I can have a handler on the datagridview for on_click but I'd like to keep this way for simplicity of code). I want to be able to set the forecolor/backcolor of a DataGridViewButtonCell. DataGridViewRow dgvRow = new DataGridViewRow(); dgvRow = (DataGridViewRow)dgv.Rows[0].Clone(); dgvRow.Cells[0].Value = filename; dgvRow.Cells[0

C#winform的datagridview去除列标头自带的排序,去除初始选中状态,添加自定义checkbox

雨燕双飞 提交于 2020-01-17 13:48:08
//去除datagridview列表头排序 foreach (DataGridViewColumn item in dataList.Columns) item.SortMode = DataGridViewColumnSortMode.NotSortable; //去掉datagridview初始选中行 dataList.ClearSelection();//dataList,datagridview的Name //遍历datagridview中的行,dataList-datagridview的Name List<UCCheckBox> ckBox = new List<UCCheckBox>();//checkbox列表 for (int i = -1; i < dataList.Rows.Count; i++) { UCCheckBox ckBoxNew = new UCCheckBox();//自定义控件checkbox,可以换成你自己的控件 ckBoxNew.TextValue = ""; ckBoxNew.Checked = false; //给checkBox确定所在行位置 Rectangle rect = this.dataList.GetCellDisplayRectangle(-1, i, true);//-1行标题所在列 //ckBox.Size = new

Cells show the value member (ID) instead Display member

╄→尐↘猪︶ㄣ 提交于 2020-01-17 12:24:28
问题 I'm currently working with C# and I have the following code to set a ComboBox column inside a DGV: // Add the values of the combo box dgvcbGeneric.DataSource = dtDataSource; dgvcbGeneric.ValueMember = "ID"; dgvcbGeneric.DisplayMember = "Value"; dgvcbGeneric.DataPropertyName = strColumn; dgvcbGeneric.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox; dgvcbGeneric.DisplayStyleForCurrentCellOnly = true; // vGenericCMB.SortMode = DataGridViewColumnSortMode.Automatic dgvcbGeneric

Winforms - How to create new tab and TabPage from current form to MainWindow form

戏子无情 提交于 2020-01-17 10:02:10
问题 I have a MainWindow form which contains TabControl component where dynamicly on click on menuItem I create a new tab and TabPage . The new created TabPage contains a new Form . The new opened TabPage , which contains the new Form en. Products have DataGridView with products list. When I double click on a cell in the DataGridview from Products form I want to open new tabPage to Mainwindow . dataGridView1_CellContentDoubleClick -> open new tab in main window In MainWindow I create: private void

Winforms - How to create new tab and TabPage from current form to MainWindow form

有些话、适合烂在心里 提交于 2020-01-17 10:01:16
问题 I have a MainWindow form which contains TabControl component where dynamicly on click on menuItem I create a new tab and TabPage . The new created TabPage contains a new Form . The new opened TabPage , which contains the new Form en. Products have DataGridView with products list. When I double click on a cell in the DataGridview from Products form I want to open new tabPage to Mainwindow . dataGridView1_CellContentDoubleClick -> open new tab in main window In MainWindow I create: private void

Why can't I bind a list of custom objects to datagridview?

≯℡__Kan透↙ 提交于 2020-01-17 08:10:56
问题 I have looked through your questions as well as elsewhere on the internet for the past two hours and cannot find a solution for my problem anywhere, or at least I didn't understand it if I did. I apologize in advance if this appears redundant or inane. Let me be clear: the issue is that I am somehow NOT implementing the approach correctly, but I understand (or think I do) how it is supposed to be done. I have a gridview on a form in which I want to display custom objects representing