[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

DataGridView appearance

Posted on 2006-11-05
6
Medium Priority
?
771 Views
Last Modified: 2008-02-01
Hello all,
Be default, a data grid view which is presenting a data in two columns, has "three" columns. The first column (left-most) just shows an arrow head on the active row, and allows us to select rows, etc. Is there a way to hide this column?
Also, I was wondering of adding a column to the end with a "X" image in it, which, when clicked, deleted that row from the data grid view.
Please advice
Huji
0
Comment
Question by:huji
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 17876750
Hi huji,

to hide a column, see http://msdn2.microsoft.com/en-gb/library/0c24a0d7(VS.80).aspx

Cheers!
0
 
LVL 34

Expert Comment

by:Sancler
ID: 17876915
To hide the leftmost column, the one you are talking about, set the .RowHeadersVisible = False in the datagridview's property window.

As to the idea of the additional column at the end, I'm not sure what the question is.  Here's a link about adding columns

   http://msdn2.microsoft.com/en-us/library/dyyesckz(VS.80).aspx

and this is the sort of code you would need when your X image was clicked on
   
        Dim drv As DataRowView = BindingContext(myDataGridView.DataSource).Current
        drv.Delete()

Roger
0
 
LVL 14

Author Comment

by:huji
ID: 17876933
Sancler, I want the datagird to appear like this:

name           surname            age
=============================
jack             smith                 13                 x
john             smith                 27                x

And pressing the x button should delete the row. It can be an image or a button, etc.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 14

Author Comment

by:huji
ID: 17876971
0
 
LVL 34

Accepted Solution

by:
Sancler earned 2000 total points
ID: 17876998
Code like this will add the column

        Dim dc As New DataGridViewButtonColumn
        dc.Text = "X"
        dc.UseColumnTextForButtonValue = True
        dc.HeaderText = "Delete"
        myDataGrid.Columns.Add(dc)

And code like this in the datagridview's Cell_Click event will do the deletion

        If e.ColumnIndex = 4 Then '<<< SEE NOTE BELOW
            Dim drv As DataRowView = BindingContext(dgvMain.DataSource).Current
            drv.Delete()
        End If

The 4 there is based on the pattern you used as an example.  You might have to alter it if there are more or less columns before the Delete column that has been added.  And I've included no refinements like checking if a header cell, or a new row cell, has been clicked.  But that's the idea.

Roger
0
 
LVL 14

Author Comment

by:huji
ID: 17890326
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question