473,397 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Merge column on datagridview C#

After obtaining the meeting area and meeting time. but i want to merge all columns from start time to end time into a single cell as shown handle the code merger column that I don't know how to do. Use dataGridView1_CellPainting event of the datagridview, don't know how to call the condition after loading the color area showing the meeting time in the dataGridView1_CellPainting event event of the datagridview calls the condition of the function: selectAreaColor() via the dataGridView1_CellPainting event of the datagridview.

Expand|Select|Wrap|Line Numbers
  1. private void selectAreaColor()
  2. {
  3.     string starttime1 = cboStarttime.Text;
  4.     string stoptime1 = cboStoptime.Text;
  5.     // Get the start time and end time inputs and the selected meeting room
  6.     DateTime startTime = DateTime.ParseExact(starttime1, "HH:mm", null);
  7.     DateTime endTime = DateTime.ParseExact(stoptime1, "HH:mm", null);
  8.     string selectedRoom = cboRoom.SelectedItem.ToString();//
  9.  
  10.     // Loop through the rows in the DataGridView and find the matching row
  11.  
  12.     foreach (DataGridViewRow row in grdMeeting.Rows)
  13.     {
  14.         if (row.Cells[0].Value.ToString() == selectedRoom)
  15.         {
  16.             int rowIndex = row.Index;
  17.             // Loop through the columns and compare the start and end times with the time slots
  18.             for (int i = 1; i < grdMeeting.Columns.Count; i++)
  19.             {
  20.                 DateTime columnTime;
  21.                 try
  22.                 {
  23.                     columnTime = DateTime.ParseExact(grdMeeting.Columns[i].HeaderText, "HH:mm", CultureInfo.InvariantCulture);
  24.                 }
  25.                 catch (Exception ex)
  26.                 {
  27.                     continue;
  28.                 }
  29.                 //DateTime columnTime = DateTime.ParseExact(grdMeeting.Columns[i].HeaderText, "HH:mm", null);
  30.                 string _HeaderText = grdMeeting.Columns[i].Name.ToString();
  31.                 if (startTime == columnTime)//|| endTime == columnTime
  32.                 {
  33.                     //how call condition here to event CellPainting
  34.                     grdMeeting.Rows[rowIndex].Cells[_HeaderText].Style.BackColor = Color.Blue;//here condition and get area data color
  35.  
  36.                     if (startTime == endTime)
  37.                         return;
  38.                     else
  39.                         startTime = startTime.AddMinutes(30);
  40.  
  41.                 }
  42.             }
  43.         }
  44.     }
  45. }
Mar 28 '23 #1
0 1239

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Rich | last post by:
Hello, I am reading data from a sql server table that is under replication. This table has the replicatin GUID column that is generated with replicatin. I am reading the data from a...
7
by: Mitchell S. Honnert | last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the DataGridView? If not, is there an easy way to duplicate the DataGridTableStyle's functionality for the DataGridView? Here's...
1
by: osmarjunior | last post by:
I want to create columns in my DataGridView just like that: ______________________________________ |________________Taxes________________| |_______Tax 1_______|______Tax 2______| | 3,50 ...
1
by: Saravanan | last post by:
Hi, I am using DataGridView for displaying data I want to some idea about the following 1. How to split and merge cells in DataGridView 2. How to place column header in the bottom of the cell...
5
by: Roger | last post by:
I am trying to do a 'simple' task in a DGV control. The problem is this. I have an unbound DGV with all 'AllowUser' options disabled. RowHeader.Visible=False ColumnHeader.Text is labelled as...
2
by: Fir5tSight | last post by:
Hi All, I have a column defined as integer indicating a status. For instance, "1" is pass and will display a green light, while "2" is fail and should display a red light. I use a stored...
9
by: active | last post by:
I need a control that displays a grid of rectangles. That is, like a brick wall except the rectangles are lined up. In VB6 I used such a control (may have been called FlexGrid but I'm not...
0
by: Lloyd Sheen | last post by:
I have been trying for last couple of hours, googling etc to find how to use a simple one column datagridview where the one and only column is a dropdown combobox. I have not been successful , I...
2
by: frenzy99 | last post by:
Can someone suggest a way to Sort two halves of DataGridView (based on the same column/criteria) and then merge the two sorted halves. say the datagrid view has 10 rows (with name/string) 1.D...
0
by: TiloW | last post by:
I got a problem with a DataTable handling an object defined by myself (Position). The object stores some data and overwrites ToString, Equals and GetHashCode. Further it provides the static...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.