[FiddlerCore]DataGridView bind colum to Oflags

0 Answers 65 Views
FiddlerCore
Chetan
Top achievements
Rank 1
Chetan asked on 02 Aug 2021, 11:39 AM

[FiddlerCore]

how to bind datagridview to  Oflags

i have oflag["Deviation"]. how do i bind this to a datagridview

            dataGridView1.Columns[0].Name = "id";
            dataGridView1.Columns[0].HeaderText = "id";
            dataGridView1.Columns[0].DataPropertyName = "id";
            dataGridView1.Columns[1].Name = "fullUrl";
            dataGridView1.Columns[1].HeaderText = "fullUrl";
            dataGridView1.Columns[1].DataPropertyName = "fullUrl";
            dataGridView1.Columns[2].Name = "LocalProcess";
            dataGridView1.Columns[2].HeaderText = "LocalProcess";
            dataGridView1.Columns[2].DataPropertyName = "LocalProcess";
            dataGridView1.Columns[3].Name = "oFlags";
            dataGridView1.Columns[3].HeaderText = "oFlags";
            dataGridView1.Columns[3].DataPropertyName = "oFlags[Deviation]";
           
            dataGridView1.AutoResizeColumn(0);
Nick Iliev
Telerik team
commented on 03 Aug 2021, 10:17 AM

What is dataGridView in your code - is this a WinForms application with DataGridView control? If so, you will need to use the dataSource to bind your data. See in the official WinForms documentation and here.
Lini
Telerik team
commented on 03 Aug 2021, 11:32 AM

You should be able to manually set the value of your flags column using an event. First remove the line:
dataGridView1.Columns[3].DataPropertyName = "oFlags[Deviation]";
and replace it with:
dataGridView1.DataBindingComplete += new DataGridViewBindingCompleteEventHandler(dataGridView1_DataBindingComplete);
Then, add the handler in your code to set the value:
void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
    foreach (DataGridViewRow row in dataGridView1.Rows)
    {
        var flags = ((Session)row.DataBoundItem).oFlags;
        row.Cells["oFlags"].Value = flags["Deviation"];
    }
}
Another way is to bind your DataGridView control to data that is already processed - i.e. create a new class, which only contains an object with the properties and values you need and use it instead of the Session object. This way you can set a value for the Deviation flag when you transform the Session object to the custom object you will use for the DataGridView.
Chetan
Top achievements
Rank 1
commented on 03 Aug 2021, 04:33 PM

Thanks for the input. this has solved the problem

No answers yet. Maybe you can help?

Tags
FiddlerCore
Asked by
Chetan
Top achievements
Rank 1
Share this question
or