How to disable RowHeader on a DataGridView











up vote
0
down vote

favorite












How can I prevent from clicking or selecting RowHeaders?

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 RowHeaders, but I want to show RowHeaders 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 RowHeaders and not let people select RowHeaders?



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();
}









share|improve this question
























  • Do not call a DataGridViewa 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




    @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















up vote
0
down vote

favorite












How can I prevent from clicking or selecting RowHeaders?

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 RowHeaders, but I want to show RowHeaders 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 RowHeaders and not let people select RowHeaders?



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();
}









share|improve this question
























  • Do not call a DataGridViewa 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




    @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













up vote
0
down vote

favorite









up vote
0
down vote

favorite











How can I prevent from clicking or selecting RowHeaders?

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 RowHeaders, but I want to show RowHeaders 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 RowHeaders and not let people select RowHeaders?



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();
}









share|improve this question















How can I prevent from clicking or selecting RowHeaders?

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 RowHeaders, but I want to show RowHeaders 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 RowHeaders and not let people select RowHeaders?



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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 23:16









zx485

12.9k122845




12.9k122845










asked Nov 9 at 22:05









Helen Tekie

9818




9818












  • Do not call a DataGridViewa 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




    @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 DataGridViewa 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




    @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 DataGridViewa 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 DataGridViewa 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Schultheiß

Verwaltungsgliederung Dänemarks

Liste der Kulturdenkmale in Wilsdruff