datagridview

1. DataGridView设置字体、行高、列宽、单列居中

筅森魡賤 提交于 2020-02-08 00:31:01
DataGridView 表格内容 的 列宽 、 行高 、 字体 的设置,设置某一列居中。一般地,会将行高设为统一的,列宽根据不同情况设定。 [csharp] view plain copy print ? // 调整字体 dataGridView1.Font = new Font( "宋体", 11); // 调整行高 //dataGridView1.Rows[0].Height = 100; dataGridView1.RowTemplate.Height = 30; dataGridView1.Update(); // 调整列宽,注意autosizecolumnsmode属性不能设置为fill dataGridView1.Columns[0].Width = 70; dataGridView1.Columns[1].Width = 360; dataGridView1.Columns[2].Width = 100; dataGridView1.Columns[3].Width = 239; // 设置某一列居中 dataGridView1.Columns[4].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; // 调整字体 dataGridView1.Font = new Font

DataGridView控件中显示图片及其注意事项

扶醉桌前 提交于 2020-02-08 00:29:12
windows Forms编程里面有一个DataGridView控件,它不光是可以显示数据,可以显示按钮,复选框,甚至还可以显示图片。这些图片可以来自于数据库(用二进制的方式存储的),也可以来自文件系统。下面是一个例子 【假设你有一个windows程序,并且窗体上有一个DataGridView控件,这个控件只有一个列(名称为Image),类型为DataGridViewImageColumn】 public Form1() { InitializeComponent(); GetData(); } private void GetData() { foreach (string s in Directory.GetFiles(@"E:\My Documents\图片收藏\表情","*.gif")) { this.demoGrid.Rows.Add(s);//注意,虽然字段类型是Image,但我们这里只给它传一个图片路径过去,真正读取图片是由下面的事件处理程序做的 } } /// <summary> /// 这个事件就在尝试对单元格进行格式化的时候触发。在这里设置真正的图片 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void demoGrid

making chart from datagridview

懵懂的女人 提交于 2020-02-07 07:15:28
问题 I have a datagridview which user fill it. the result is calculated and return to read only columns of datagridview. I want to make a chart for two columns of my datagridview. but I don't save datagridview in a table because there is previous results in the table! somebody told me for creating chart you should save your datagridview to a table but in this case you should convert datagridview to datatable and then clear it! please tell me what should I do! :( this is my code for creating chart

making chart from datagridview

天大地大妈咪最大 提交于 2020-02-07 07:15:21
问题 I have a datagridview which user fill it. the result is calculated and return to read only columns of datagridview. I want to make a chart for two columns of my datagridview. but I don't save datagridview in a table because there is previous results in the table! somebody told me for creating chart you should save your datagridview to a table but in this case you should convert datagridview to datatable and then clear it! please tell me what should I do! :( this is my code for creating chart

Bound DataGridView not updating to display information + sorting issues

一笑奈何 提交于 2020-02-05 13:16:29
问题 I have a bound DataGridView1 and several bound TextBoxes and DateTimePickers. Everything is working well, except when I try to accomplish these two things in conjunction: Sort the DataGridView1 by a specific column (date). Change that same column date based on a DateTimePicker. The idea is that I am sorting my DataGridView1 like so (I set this in Form Load): DataGridView1.Sort(DataGridView1.Columns(45), ListSortDirection.Ascending) (Column 45 is just my "MyDateColumn" column) And later on,

Bound DataGridView not updating to display information + sorting issues

狂风中的少年 提交于 2020-02-05 13:16:12
问题 I have a bound DataGridView1 and several bound TextBoxes and DateTimePickers. Everything is working well, except when I try to accomplish these two things in conjunction: Sort the DataGridView1 by a specific column (date). Change that same column date based on a DateTimePicker. The idea is that I am sorting my DataGridView1 like so (I set this in Form Load): DataGridView1.Sort(DataGridView1.Columns(45), ListSortDirection.Ascending) (Column 45 is just my "MyDateColumn" column) And later on,

fix a columns width when a list is bound to a datagridview

穿精又带淫゛_ 提交于 2020-02-04 05:13:09
问题 I have a list that I have bound to a datagridview. I want the first column to be a fixed size. The data is bound to the dataGridView and I can't seem to find a way to access an individual colums properties. if I try myDatagridview.colums[0] I get an index out of bounds, since it says the columns count is 0. private DataGridView setUpDataGrid(List<NVRlineVal> _NVRData) { //setup dataGridView DataGridView NVRDataGridView = new System.Windows.Forms.DataGridView(); NVRDataGridView

fix a columns width when a list is bound to a datagridview

我与影子孤独终老i 提交于 2020-02-04 05:12:17
问题 I have a list that I have bound to a datagridview. I want the first column to be a fixed size. The data is bound to the dataGridView and I can't seem to find a way to access an individual colums properties. if I try myDatagridview.colums[0] I get an index out of bounds, since it says the columns count is 0. private DataGridView setUpDataGrid(List<NVRlineVal> _NVRData) { //setup dataGridView DataGridView NVRDataGridView = new System.Windows.Forms.DataGridView(); NVRDataGridView

Create a Tiff Bitmap file from a DatagridView

别说谁变了你拦得住时间么 提交于 2020-02-02 06:23:44
问题 I want to create a Tiff file from a Datagridview. I was able to get the Datagridview to a Tiff file, however I just want the Rows and Columns and nothing else. Is this possible without using 3rd party Tool? Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load DataGridView1.Rows.Add(New String() {"Value1", "Value2", "Value3"}) Dim height As Integer = DataGridView1.Height DataGridView1.Height = DataGridView1.RowCount * DataGridView1.RowTemplate.Height Dim bitmap As

DataGridView 索引,添加列

家住魔仙堡 提交于 2020-02-02 00:49:18
问题1:DataGridView绑定DataTable之后,在界面排序,选择若干行,此时选中的行的index与DataTable中的index不一致,这样若想要对其对应的行进行修改操作,将会造成错误。 Sol: 首先将选中的DataGridView行的DataBoundItem属性转换为DataRowView, 然后通过对应的DataTable中的取出索引。 1 DataRowView drv = dataGridView.SelectedRows[0].DataBoundItem as DataRowView; 2 int index = dataTable.Rows.IndexOf(drv.Row); 这是因为DataRowView对象中,有一个Row属性,获取 正被查看的 DataRow ,那么就可以在DataRow所在的表中找到它的索引啦。 问题2:为什么foreach遍历DataTable或者DataGridView对行进行增删修改的操作,会造成索引错误的问题? Sol: 这是因为foreach循环是从第一位开始遍历,如果对某一行进行删除操作,那么该行后面的DataRow(DataGridViewRow)的索引会提前一位,也即是说,DataRow(DataGridViewRow)的index是会实时变化的,因此会出错。比如索引为3被删除,那么删除后4的索引就变成3了