プログラムでバインドしているWindows DataGridViewに1つの編集列と別の削除列があります.1つの列「編集」と別の「削除」があり、どちらも「ID」にバインドされているとします..これらをマージしたい「編集」と「削除」のリンクがある「編集/削除」の両方の列..しかし、C#ウィンドウフォームプロパティのVS Studio 2010のTableLayoutPanelプロパティに従って、1つのセルに2つのコントロールを持つことはできません..方法C# Windows フォーム コードを使用してこのシナリオを実現する
コード:-
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);
}
}