datagridview

Sort Datagridview by Two Columns

我的梦境 提交于 2019-12-25 16:55:36
问题 I have a datagridview that contain 3 columns. But I hv not bind a datasource to datagridview. It has three columns. EmpName,InTime,OutTime I can edit EmpName in datagridview. I want to sort the content in the datagridview after i edit a row. I want to sort first by EmpName and then by InTime. The time is in AM , PM Time format (Ex: 2:00 PM). I can sort data by only one column. I have used, dgvSchedule.Sort(dgvSchedule.Columns[0],ListSortDirection.Ascending); But how to sort by multiple

C# Datagridview - Combobox With Different Values Per Row

☆樱花仙子☆ 提交于 2019-12-25 16:45:14
问题 I've done my usual google searching but all of the topics I came across didn't seem to be doing this in the same way I am doing, or looking to do it in the same way. The closest I could find was this https://www.experts-exchange.com/questions/23555139/How-to-filter-values-in-DataGridViewComboBoxColumn.html Ignoring that this is VB and I'm working in C#, they have the dataset/source etc set at the top and creating new columns on a line by line basis, whereas I'm creating my data in the grid

Why am I crashing and getting the wrong day of the week?

余生长醉 提交于 2019-12-25 16:39:59
问题 My system clock is 9/16/2014 (Tuesday) But in code, I'm always jumping to Monday. DayOfWeek dow = new DateTime().DayOfWeek; int columnNumber = 0; columnNumber = columnNumber + 0; foreach ( DataGridViewRow row in dataGridView1.Rows ) { switch ( dow ) { case DayOfWeek.Monday: columnNumber = 4; if ( (bool) row.Cells[4].Value == true ) // crashing here with NullReferenceException { row.Cells["activeTodayDataGridViewCheckBoxColumn"].Value = true; } break; I have a DataGridView Columns 0—3 are Text

Leading zero in DataGridView

陌路散爱 提交于 2019-12-25 14:48:55
问题 I want to display a number with a leading zero in a DataGridView but i don't know how. for example: 3910323 → 03910323 I've tried to add a leading zero to an int/string in a DataGridView and for some reason the DataGridView emits the zero. How can i format the cells in a way that a leading zero will be displayed? This is my code: string number = dgvCustomers[0, 0].Value.ToString(); number = "0" + number; dgvCustomers[0, 0].Value = number; 回答1: Try using dgv.Columns["myColumn"]

Copy the contents of a DataGridView in to excel

元气小坏坏 提交于 2019-12-25 12:56:08
问题 I found some examples of how to create a excel file from a data grid view, however those just create the file. What I would like to do is have excel open, with a unsaved worksheet, and have the content of the data grid view (including header names) pasted in to the worksheet after pressing a "Export to Excel" button. Basically I want to automate what happens when you do a copy and paste from a data grid view in to excel. Any suggestions on how to do this? 回答1: Take a look at this tutorial,

manipulate DataGridView

为君一笑 提交于 2019-12-25 12:51:14
问题 please if someone can help :( ,I'm looking at first to combine date and times (ex: ( DatetaskStart ,TimetaskStart) , (DatetaskEnd ,TimetaskEnd)). And throughout my dategridview I want make a subtraction between combinaision obtained ((date, time) of the beginning of the task ) and ((date,time) of end the task) and finally get the total times in hours of all the tasks obtained. Dim sql As String = "select id_task, DatetaskStart ,TimetaskStart , DatetaskEnd ,TimetaskEnd from task where id_task

How can I validate input to the edit control of a cell in a DataGridView?

筅森魡賤 提交于 2019-12-25 12:09:50
问题 It appears that the only way to capture the keypress events within a cell of a DataGridView control in order to validate user input as they type, is to use the DataGridView controls OnEditControlShowing event, hook up a method to the edit control's (e.Control) keypress event and do some validation. My problem is that I've built a heap of custom DataGridView column classes, with their own custom cell types. These cells have their own custom edit controls (things like DateTimePickers and

Can't add rows to DataGridView after adding the first one

南笙酒味 提交于 2019-12-25 12:09:24
问题 I have this code: private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { db database = new db(); database.set_connection(Properties.Settings.Default.connection); DataTable result = database.search(textBox1.Text, "", ""); if (result.Rows.Count == 0) { MessageBox.Show("nothing found", "error", MessageBoxButtons.OK, MessageBoxIcon.Information); textBox1.SelectAll(); textBox1.Focus(); } else { if (dataGridView1.Rows.Count == 0) { DataGridViewRow row = new

Datagridview ComboBoxCell set default value?

我只是一个虾纸丫 提交于 2019-12-25 11:54:58
问题 I have a datagridview with lots of data, and when I add a new line, the first column's last row creates a new ComboBoxCell which contain four items. But I can't set the default value ("DropDown") for the combobox. Every time I must manually select "DropDown". What is the solution? DataGridViewComboBoxCell dgvCell = new DataGridViewComboBoxCell(); dgv[1, dgv.Rows.Count - 1] = dgvCell; string[] controltype = {"DropDown", "CheckBoxList", "ListControl", "Tree" }; dgvCell.DataSource = controltype;

Datagridview ComboBoxCell set default value?

老子叫甜甜 提交于 2019-12-25 11:54:21
问题 I have a datagridview with lots of data, and when I add a new line, the first column's last row creates a new ComboBoxCell which contain four items. But I can't set the default value ("DropDown") for the combobox. Every time I must manually select "DropDown". What is the solution? DataGridViewComboBoxCell dgvCell = new DataGridViewComboBoxCell(); dgv[1, dgv.Rows.Count - 1] = dgvCell; string[] controltype = {"DropDown", "CheckBoxList", "ListControl", "Tree" }; dgvCell.DataSource = controltype;