datagridview

Update Datagridview From Another Form

為{幸葍}努か 提交于 2020-01-11 04:05:10
问题 First I should say i saw this link : How to refresh datagridview when closing child form? And i did like this: (i have datagridview in Form1) Form1: public void FillDataGridView(DataTable dt1) { bindingSource1.DataSource = dt1; bindingSource1.ResetBindings(false); dataGridView1.DataSource = bindingSource1; //here i checked number of rows of dt1 and it shows the correct value } Form2: SqlConnection cnn = new SqlConnection(@"My connection string"); private Form1 Handled_frm1; public Form2(Form1

How to set the “insert new row” as first row in DataGridView

烂漫一生 提交于 2020-01-11 02:36:05
问题 I am trying to get the DataGridView to render the "insert new row" row as the first row in the grid instead of the last row. How do I go about doing that, is it even possible in the control? 回答1: I don't think there is any way to move the "new row" row to the top of the data grid. But, what if you left the top row empty and as the data filled in move the row down as appropriate? In other words, make your own "new row" row, which is just first row in the grid and add new blank rows above when

c# DataGridView分页功能的实现

旧城冷巷雨未停 提交于 2020-01-10 15:51:22
首先,拖两个控件BindingNavigate、BindingSource; 1.定义公共变量 int pageCount;//总页数 int pageRSize;//每页显示的行数 int RowMax;//总共行数 int currentR;//当前行号 int currentP;//当前页号 DataTable dat = new DataTable(); 2.  获取数据 DataBaseConnection connection = new DataBaseConnection(); //建立数据库引擎连接,注意数据表(后缀为.db)应放在DEBUG文件下 string sql = ("select 测线名称,起始桩号,X坐标,Y坐标,方向角,间隔,个数,线号增量,测线间距 from line where 所属项目='" + project + "'"); //建立适配器,通过SQL语句去搜索数据库 DataSet myds = connection.getDataSet(sql); dat = myds.Tables[0]; SetIni(); 3.设置 private void SetIni(int p) { pageRSize = 10; if (p == 1) { currentP = 1; currentR = 0; } else { currentP = p;

Why DataGridColumn not getting removed from DataGridView

醉酒当歌 提交于 2020-01-10 05:45:15
问题 I have custom DataGridView control and in that control there is RefreshGrid() method which fill DataGridView by using DataSource. Now I am tring to remove few columns from that DataGridView after DataSource binding but unable to remove those, those column not getting removed but add at the end of DataGridView, when I call RefreshGrid() method again then those column get removed from DataGridView . Here is code for method RefreshGrid() public void RefreshGrid() { DataTable _table =

Number Format For Datagridview in C#

泄露秘密 提交于 2020-01-10 05:26:46
问题 I want to set the datagridview values in number format. Currently I am getting this: I want something like this: I have used this code: dgvmain.DefaultCellStyle.Format = "#.##0"; And this code dgvmain.Columns["Amount"].DefaultCellStyle.Format = "#.##0"; But neither of this working. 回答1: You can Set you Format String using CellStyle Builder an set the Custom format to # mm How to do it : Right click on Grid, then Properties In the property window, click the button that will popup up the Edit

sometimes I want to hide buttons in a DataGridViewButtonColumn

喜欢而已 提交于 2020-01-10 04:57:07
问题 I have a DataGridView which was the subject of a previous question (link). But sometimes the Button is null . This is fine. But if it is null, is there any way I can optionally remove/add (show/hide?) buttons to the DataGridViewButtonColumn of Buttons like this: +------------+------------+ | MyText | MyButton | +------------+------------+ | "do this" | (Yes) | | "do that" | (Yes) | | FYI 'blah' | | <---- this is where I optionally want no button | "do other" | (Yes) | +------------+----------

DataReader 绑定DataGridView的方式

江枫思渺然 提交于 2020-01-10 04:11:32
DataReader 绑定DataGridView有两种方式 第一种:借助于BindingSource sqlDataReader Sdr=通过查询函数得到的sqlDataReader类型的数据; BindingSource Bs=new BindingSource() ; Bs.DataSource=Sdr; DataGridView.DataSource=Bs; 第二种:借助DataTable sqlDataReader Sdr=通过查询函数得到的sqlDataReader类型的数据; DataTable Dt=new DataTable(); Dt.Load(Sdr); DataGridView.DataSource=Bs; 获取DataGridView的选择的行 例如将选择的行的第一列的值转换成string的类型并赋给Num string Num=Convert.ToString(DataGridView[0,DataGridView.CurrentCell.RowIndex].Value); 这样选中的行的第一列就转换成了string类型的数据,可以通过SQL语句进行其他的操作。 来源: https://www.cnblogs.com/PocketZ/archive/2011/11/17/2252914.html

DataGridView: How to select an entire Column and deselect everything else?

我们两清 提交于 2020-01-10 03:58:09
问题 I've been trying to find out how to select all cells under a Column with a 'mouse right click+menu+Select this Column'... MSDN isn't helping much... I get this error when I try to change selection mode: DataGridView control's SelectionMode cannot be set to FullColumnSelect while it has a column with SortMode set to DataGridViewColumnSortMode.Automatic. Thanks, Y_Y 回答1: Loop through the cells in the column and set their Selected property to true. It sounds horrible, but I believe it's the only

Adjust DataGridView's columns to fill available space if the grid is smaller and use scroll in case the grid bigger than the space available

余生颓废 提交于 2020-01-10 02:50:12
问题 I want to adjust all columns of a DataGridView according to the required space to show all its data completely. If the space required is smaller than the available space i want the grid to fill this exceeding space, but if the available is space is not enough to display properly all columns i want to DataGridView create automatically a scroll. Is there an easy way to do this? 回答1: Click over the DataGridView and select "Edit Columns...", then go to "Layout" and set "AutoSizeMode" to "Fill".

datagridview

谁说胖子不能爱 提交于 2020-01-10 02:28:39
本文将向大家介绍在C#中如何通过编程实现让DataGridView控件隔行显示不同的颜色……   如果该dataGridView是跟数据库绑定的,则可以触发DataBindingComplete事件: private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)   {   if (this.dataGridView1.Rows.Count != 0)   {   for (int i = 0; i < this.dataGridView1.Rows.Count; )   {   this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Pink;   i += 2;   }   }   }   如果没有绑定数据库,那么当dataGridView中的数据有所改变或显示的时候可以添加以下的代码: if (this.dataGridView1.Rows.Count != 0)   {   for (int i = 0; i < this.dataGridView1.Rows.Count; )   {   this.dataGridView1.Rows