Merge Edit and Delete columns in one Column in Windows Forms using VS2010 , C# Code

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have one Edit column and another Delete column in a Windows DataGridView which I am binding programatically .. Say I have one column " Edit " and another " Delete " , which both are bound to "ID" .. Now I want to merge these both columns as " Edit/Delete"
where there will be Links for " Edit " and "Delete " .. but as per VS Studio 2010s TableLayoutPanel property of C# windows forms property , I can not have two controls in one Cell .. How to achieve this scenario using C# Windows Forms code
<pre class="prettyprint public frmTopicSectionManagement()

{

InitializeComponent();

PopulateTopicList();

PopulateGridView();

}

private void PopulateGridView()

{

try

{

string PYear = "";

int pId;

int TopicId = Convert.ToInt32(((Topiclist)cmbTopics.SelectedItem).TopicId);

PYear = StartUp.PlanYear.ToString();

pId = StartUp.ProductTypId;

TopicSectionLookup objTopicSection = new TopicSectionLookup();

if (repo.GetAllTopicSections() != null && TopicId == -1 && PYear != "")


{

GridView_TopicSection.DataSource = repo.GetAllTopicSectionDisplayTopicTitle(pId, PYear).ToList(); GridView_TopicSection.Columns["ProductType"].Visible = false;

GridView_TopicSection.Columns["Year"].Visible = false;
PopulateAllGridView();

}
else if (repo.GetAllTopicSections() != null)
{
GridView_TopicSection.DataSource = repo.GetAllTopicsForSectionManagement(TopicId, pId, PYear).ToList();
GridView_TopicSection.Columns["ProductType"].Visible = false;
GridView_TopicSection.Columns["Year"].Visible = false;
PopulateAllGridView();
}
else
{
return;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void PopulateAllGridView()
{
try
{
//Add Update Button to DataGridView(Problems here)
if (!GridView_TopicSection.Columns.Contains("Update") || !!GridView_TopicSection.Columns.Contains("Delete"))
{
DataGridViewLinkColumn updateColumn = new DataGridViewLinkColumn();
updateColumn.Name = "Edit";
updateColumn.HeaderText = "Update";
updateColumn.Text = "Edit";
updateColumn.Width = 50;
updateColumn.DividerWidth = 0;
updateColumn.UseColumnTextForLinkValue = true;
GridView_TopicSection.Columns.Add(updateColumn);

// Add Delete Button to GridView (and here)
DataGridViewLinkColumn deletecolumn = new DataGridViewLinkColumn();
deletecolumn.Name = "Delete";
deletecolumn.HeaderText = "Delete";
deletecolumn.Text = "Delete";
deletecolumn.Width = 103;
deletecolumn.UseColumnTextForLinkValue = true;
GridView_TopicSection.Columns.Add(deletecolumn);
}

GridView_TopicSection.Columns["TopicId"].Visible = false;
GridView_TopicSection.Columns["TopicSectionLookupId"].Visible = false;
GridView_TopicSection.Columns["TopicTitle"].Visible = true;
GridView_TopicSection.Columns["TopicTitle"].Width = 200;
GridView_TopicSection.Columns["SectionText"].Visible = true;
GridView_TopicSection.Columns["SectionText"].Width = 200;
GridView_TopicSection.Columns["Year"].Visible = false;
GridView_TopicSection.Columns["ProductTypeId"].Visible = false;
GridView_TopicSection.Columns["IsActive"].Visible = true;
GridView_TopicSection.Columns["IsActive"].Width = 80;
GridView_TopicSection.Columns["IsBenifit"].Visible = true;
GridView_TopicSection.Columns["IsBenifit"].Width = 80;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

}
[/code]
<br/>
<img alt="" src="http://social.msdn.microsoft.com/Forums/getfile/119603


View the full article
 
Back
Top