Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi:
I have a question regarding DataGridViews. I posted this problem here on line and a kind person solve it for me.
Unfortunately, the next problem is a little more difficult. I am posting the first problem so that anyone who reads this posting
will understand the background of this program. Note this first section was solved. The second section is where I need assistance.

First problem:
I have created a calendar of 3 years dynamically. I have a DataGridView for each day. So, for three years, I have approximately 1095 DataGridViews. Each DataGridView has a name associated with it. The name is the date.
C#
DataGridView weekDataGridView = new DataGridView();

gridViewName = currentDate.Date.ToString(nameFormat);
String offDate = currentDate.ToString("yyyy-MM-dd");
weekDataGridView.Name = offDate;

So, for this calendar, my last name is for “2016-01-02” because that is the last DataGridView that I created.

The problem is that I cannot return the name of the current DataGridView that I am clicking on.
C#
weekDataGridView.MouseClick += new MouseEventHandler(weekDataGridView_MouseClick);

private void weekDataGridView_MouseClick(object sender, MouseEventArgs e)
{
            weekDataGridView.Focus();

            DataGridViewRow row = weekDataGridView.CurrentRow;

            string name = GetGridName(weekDataGridView);
}
private string GetGridName(DataGridView dataGridView)
{
            string gridViewName = dataGridView.Name;

            return gridViewName;
}

Every time that I click on a DataGridView my name is 2016-01-02. Even if I click on a DataGridView from Jan 19, 2014. I still get the last DataGridView that was created.

So, I tried this approach after I created all the datagridviews,

weekDataGridView.Name = “”;

So, when I click on a DataGridView from January 19, 2014, I get null; I get null when I click on 2016-01-02 which is what I expected. Because the last name entered for the DataGridView is

weekDataGridView.Name = “”;

How do I return the date of the weekDataGridView that I am click on?


Solution:
C#
DataGridView dgv = (DataGridView)sender;
            string dgvName = dgv.Name;


Second problem: this is where I need help currently.

Brand new problem. When creating this calendar, I have a TableLayoutPanel with 4 columns and 4 rows on a tabPage, then I have the next week on the next tabPage and so on. The first row, I have labels (one in each of the 4 columns) which displays the date of the DataGridViews that are in the second row. The second row has 4 datagridviews (one in each column). The first column is for Sunday, the second column for Monday, then Tuesday and Wednesday.
The third row has labels which displays the dates for the DataGridViews in the fourth row. The fourth row has datagridviews for Thursday in the first column, second column has Friday, and third Column has Saturday. The fourth column of the fourth row has a dataGridView which will display other information related to the rowIndex that is clicked on the current weekDataGridView. I also have a label for this, which is in row 3, column 4. It will display a person’s name.

Row 1: Labels.
Row 2: weekDataGridViews

Row 3: Labels.
Row 4: weekDataGridViews


When I click on a weekDataGridView for Jan. 13, 2014 for example, my Person’s name goes to the last label that was created, which is on Jan 2, 2016 (“2016-01-02”) because that was the last label created for this calendar. Also, just from the way this project is going, I know that the data that I need to display in the 4th column, 4th row on this page will go to the last DataGridView that was created which will be right next to the “2016-01-02” weekDataGridView.
I need the Person’s name to be displayed on the Label that is in the same TableLayoutPanel as Jan 13, 2014. Likewise, I need the other information to be displayed from the rowIndex of Jan 13, 2014 to go on the 4th row, 4th column of the DataGridView on the same TableLayoutPanel.

How do I accomplish this task?

Thank you very much for your help.

Bosco
Posted
Updated 1-Mar-14 11:54am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900