How to disable RowHeader on a DataGridView
up vote
0
down vote
favorite
How can I prevent from clicking or selecting RowHeader
s?
I want that when a new user clicks on a row
or cell
, then move all information to an update Form
and it's working fine.
But, if a user clicks on a RowHeader
, then it should select all rows and generate an error.
I know I can hide RowHeader
s, but I want to show RowHeader
s and I want to prevent users from clicking on them.
I have used the SelectionMode
property of the DataGridview
and set it to CellSelect/FullRowSelect etc, but it did not help.
Is it possible to disable RowHeader
s and not let people select RowHeader
s?
Here is my code so far:
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
decimal accNo = Convert.ToDecimal(dataGridView1.Rows[e.RowIndex].Cells[0].Value);
var item = db.UserAccount.Where(a => a.AccountNo == accNo).FirstOrDefault();
txtAccountNo.Text = item.AccountNo.ToString();
txtFirstName.Text = item.FirstName;
txtLastName.Text = item.LastName;
txtAddressUpNew.Text = item.Address.ToString();
}
c# winforms datagridview rowheader
|
show 7 more comments
up vote
0
down vote
favorite
How can I prevent from clicking or selecting RowHeader
s?
I want that when a new user clicks on a row
or cell
, then move all information to an update Form
and it's working fine.
But, if a user clicks on a RowHeader
, then it should select all rows and generate an error.
I know I can hide RowHeader
s, but I want to show RowHeader
s and I want to prevent users from clicking on them.
I have used the SelectionMode
property of the DataGridview
and set it to CellSelect/FullRowSelect etc, but it did not help.
Is it possible to disable RowHeader
s and not let people select RowHeader
s?
Here is my code so far:
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
decimal accNo = Convert.ToDecimal(dataGridView1.Rows[e.RowIndex].Cells[0].Value);
var item = db.UserAccount.Where(a => a.AccountNo == accNo).FirstOrDefault();
txtAccountNo.Text = item.AccountNo.ToString();
txtFirstName.Text = item.FirstName;
txtLastName.Text = item.LastName;
txtAddressUpNew.Text = item.Address.ToString();
}
c# winforms datagridview rowheader
Do not call aDataGridView
aGridView
or aDataGrid
and vice versa!! This is wrong and confusing as those are different controls. Always call things by their right name!
– TaW
Nov 9 at 22:06
1
@TaW thank you, you are right. I have now edited my question.
– Helen Tekie
Nov 9 at 22:13
You may want to look into the SelectionMode. Change ftom the default (RowHeader) to something else..
– TaW
Nov 9 at 22:21
1
If the code you show throws an error in the dataGridView1_CellClick, as you decribe, this is where you should test for a non-negative index. You can't really/easily prevent the user clicking where he want but you can write your code to not always react or to do different things when clicking cells or headers
– TaW
Nov 10 at 0:05
1
@TaW Aha ... if (e.RowIndex > -1) .... OK, thank you. Now it's working
– Helen Tekie
Nov 10 at 0:51
|
show 7 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
How can I prevent from clicking or selecting RowHeader
s?
I want that when a new user clicks on a row
or cell
, then move all information to an update Form
and it's working fine.
But, if a user clicks on a RowHeader
, then it should select all rows and generate an error.
I know I can hide RowHeader
s, but I want to show RowHeader
s and I want to prevent users from clicking on them.
I have used the SelectionMode
property of the DataGridview
and set it to CellSelect/FullRowSelect etc, but it did not help.
Is it possible to disable RowHeader
s and not let people select RowHeader
s?
Here is my code so far:
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
decimal accNo = Convert.ToDecimal(dataGridView1.Rows[e.RowIndex].Cells[0].Value);
var item = db.UserAccount.Where(a => a.AccountNo == accNo).FirstOrDefault();
txtAccountNo.Text = item.AccountNo.ToString();
txtFirstName.Text = item.FirstName;
txtLastName.Text = item.LastName;
txtAddressUpNew.Text = item.Address.ToString();
}
c# winforms datagridview rowheader
How can I prevent from clicking or selecting RowHeader
s?
I want that when a new user clicks on a row
or cell
, then move all information to an update Form
and it's working fine.
But, if a user clicks on a RowHeader
, then it should select all rows and generate an error.
I know I can hide RowHeader
s, but I want to show RowHeader
s and I want to prevent users from clicking on them.
I have used the SelectionMode
property of the DataGridview
and set it to CellSelect/FullRowSelect etc, but it did not help.
Is it possible to disable RowHeader
s and not let people select RowHeader
s?
Here is my code so far:
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
decimal accNo = Convert.ToDecimal(dataGridView1.Rows[e.RowIndex].Cells[0].Value);
var item = db.UserAccount.Where(a => a.AccountNo == accNo).FirstOrDefault();
txtAccountNo.Text = item.AccountNo.ToString();
txtFirstName.Text = item.FirstName;
txtLastName.Text = item.LastName;
txtAddressUpNew.Text = item.Address.ToString();
}
c# winforms datagridview rowheader
c# winforms datagridview rowheader
edited Nov 9 at 23:16
zx485
12.9k122845
12.9k122845
asked Nov 9 at 22:05
Helen Tekie
9818
9818
Do not call aDataGridView
aGridView
or aDataGrid
and vice versa!! This is wrong and confusing as those are different controls. Always call things by their right name!
– TaW
Nov 9 at 22:06
1
@TaW thank you, you are right. I have now edited my question.
– Helen Tekie
Nov 9 at 22:13
You may want to look into the SelectionMode. Change ftom the default (RowHeader) to something else..
– TaW
Nov 9 at 22:21
1
If the code you show throws an error in the dataGridView1_CellClick, as you decribe, this is where you should test for a non-negative index. You can't really/easily prevent the user clicking where he want but you can write your code to not always react or to do different things when clicking cells or headers
– TaW
Nov 10 at 0:05
1
@TaW Aha ... if (e.RowIndex > -1) .... OK, thank you. Now it's working
– Helen Tekie
Nov 10 at 0:51
|
show 7 more comments
Do not call aDataGridView
aGridView
or aDataGrid
and vice versa!! This is wrong and confusing as those are different controls. Always call things by their right name!
– TaW
Nov 9 at 22:06
1
@TaW thank you, you are right. I have now edited my question.
– Helen Tekie
Nov 9 at 22:13
You may want to look into the SelectionMode. Change ftom the default (RowHeader) to something else..
– TaW
Nov 9 at 22:21
1
If the code you show throws an error in the dataGridView1_CellClick, as you decribe, this is where you should test for a non-negative index. You can't really/easily prevent the user clicking where he want but you can write your code to not always react or to do different things when clicking cells or headers
– TaW
Nov 10 at 0:05
1
@TaW Aha ... if (e.RowIndex > -1) .... OK, thank you. Now it's working
– Helen Tekie
Nov 10 at 0:51
Do not call a
DataGridView
a GridView
or a DataGrid
and vice versa!! This is wrong and confusing as those are different controls. Always call things by their right name!– TaW
Nov 9 at 22:06
Do not call a
DataGridView
a GridView
or a DataGrid
and vice versa!! This is wrong and confusing as those are different controls. Always call things by their right name!– TaW
Nov 9 at 22:06
1
1
@TaW thank you, you are right. I have now edited my question.
– Helen Tekie
Nov 9 at 22:13
@TaW thank you, you are right. I have now edited my question.
– Helen Tekie
Nov 9 at 22:13
You may want to look into the SelectionMode. Change ftom the default (RowHeader) to something else..
– TaW
Nov 9 at 22:21
You may want to look into the SelectionMode. Change ftom the default (RowHeader) to something else..
– TaW
Nov 9 at 22:21
1
1
If the code you show throws an error in the dataGridView1_CellClick, as you decribe, this is where you should test for a non-negative index. You can't really/easily prevent the user clicking where he want but you can write your code to not always react or to do different things when clicking cells or headers
– TaW
Nov 10 at 0:05
If the code you show throws an error in the dataGridView1_CellClick, as you decribe, this is where you should test for a non-negative index. You can't really/easily prevent the user clicking where he want but you can write your code to not always react or to do different things when clicking cells or headers
– TaW
Nov 10 at 0:05
1
1
@TaW Aha ... if (e.RowIndex > -1) .... OK, thank you. Now it's working
– Helen Tekie
Nov 10 at 0:51
@TaW Aha ... if (e.RowIndex > -1) .... OK, thank you. Now it's working
– Helen Tekie
Nov 10 at 0:51
|
show 7 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233848%2fhow-to-disable-rowheader-on-a-datagridview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Do not call a
DataGridView
aGridView
or aDataGrid
and vice versa!! This is wrong and confusing as those are different controls. Always call things by their right name!– TaW
Nov 9 at 22:06
1
@TaW thank you, you are right. I have now edited my question.
– Helen Tekie
Nov 9 at 22:13
You may want to look into the SelectionMode. Change ftom the default (RowHeader) to something else..
– TaW
Nov 9 at 22:21
1
If the code you show throws an error in the dataGridView1_CellClick, as you decribe, this is where you should test for a non-negative index. You can't really/easily prevent the user clicking where he want but you can write your code to not always react or to do different things when clicking cells or headers
– TaW
Nov 10 at 0:05
1
@TaW Aha ... if (e.RowIndex > -1) .... OK, thank you. Now it's working
– Helen Tekie
Nov 10 at 0:51