Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

vb.net datagridview button

Posted on 2006-10-30
2
Medium Priority
?
1,372 Views
Last Modified: 2008-01-09
I have a datagridview where I insert a button.

I call the same function many times which gets a dataset from a db, then sets it to the grid.
After that I add the button with the code below.

Each time I call the function, a new button is created, how do I only do it if it does not exist?

        Dim buttons As New DataGridViewButtonColumn()
        With buttons
            .HeaderText = "Delete"
            .Text = "Delete"
            .UseColumnTextForButtonValue = True
            .AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
            .FlatStyle = FlatStyle.Standard
            .DisplayIndex = 0
        End With
0
Comment
Question by:jackjohnson44
[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
2 Comments
 
LVL 39

Accepted Solution

by:
appari earned 2000 total points
ID: 17839921
try like this

        if not yourGridName.columns.contains("Delete") then      
        Dim buttons As New DataGridViewButtonColumn()
        With buttons
            .HeaderText = "Delete"
            .Text = "Delete"
            .name ="Delete"
            .UseColumnTextForButtonValue = True
            .AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
            .FlatStyle = FlatStyle.Standard
            .DisplayIndex = 0
        End With
        End if

0
 
LVL 6

Expert Comment

by:manch
ID: 17839922

U have to add this condition before adding the column to the Grid

the Logic is as follows :
(let DataGridView1 )

        'Here is ur code for creating a New Button Column
        Dim buttons As New DataGridViewButtonColumn()
        With buttons
            .HeaderText = "Delete"
            .Text = "Delete"
            .UseColumnTextForButtonValue = True
            .AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
            .FlatStyle = FlatStyle.Standard
            .DisplayIndex = 0
        End With

        'Here is the code for checking the existance of the column in the grid view
        Dim pbFound As Boolean = False
        Dim piCnt As Int16 = 0

        While (Not (pbFound) And (piCnt <= (DataGridView1.Columns.Count - 1)))

            If (DataGridView1.Columns(piCnt).HeaderText = "Delete") Then
                pbFound = True
            End If
            piCnt = piCnt + 1
        End While
        'If column does not exists in the datagridview1 then adding it to our datagridview1
        If (pbFound = false ) Then
            DataGridView1.Columns.Add(buttons)
        End If


Try It
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

719 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