How to bind dataset to data grid view?
Drag and drop a DataGridView control on your dialog. Create a class with properties for each column to be displayed in the DataGridView.
public class gridData
{
public string PropForCol1 { get; set; } public string PropForCol2 { get; set; } public string PropForCol3 { get; set; } public string PropForCol4 { get; set; } public gridData(string tagNumber, string tagName, string tagValue, string tagMeaning) {
this.PropForCol1 = tagNumber; this.PropForCol2 = tagName; this.PropForCol3 = tagValue; this.PropForCol4 = tagMeaning; }
}
In the function where all the datagrid values need to be populated.
List<gridData> gridDataList = new List<gridData>();
gridDataList.Add(new gridData("row1Col1"," row1Col2", "row1Col3", "row1Col4"));
gridDataList.Add(new gridData("row2Col1"," row2Col2", "row2Col3", "row2Col4")); gridDataList.Add(new gridData("row3Col1"," row3Col2", "row3Col3", "row3Col4"));
Now set the datasour to the List.
dataGridViewForValidationResult.DataSource = gridDataList;
Your are done.