C# .NET - how to bind data into GridView + WPF

Asked By Abhi Rana on 12-Aug-09 03:13 AM
 Following Code is unable to bind data into Grid

<Button Height="23" Margin="0,12,35,0" Name="button1" VerticalAlignment="Top" HorizontalAlignment="Right" Width="46" Click="button1_Click">Go</Button>

<ListView Name="listView1" Margin="0,41,0,0">

<ListView.View>

<GridView>

<GridViewColumn Header="User_Name" Width="100" DisplayMemberBinding="{Binding Path=User_Name}"/>

<GridViewColumn Header="Project_Name" Width="100" DisplayMemberBinding="{Binding Path=Project_Name}" />

<GridViewColumn Header="CD_Name" Width="100" DisplayMemberBinding="{Binding Path=CD_Name}"/>

<GridViewColumn Header="IsOracle" Width="100" DisplayMemberBinding="{Binding Path=IsOracle}" />

</GridView>

</ListView.View>

</ListView>

</Grid>

</Window>

 

private void button1_Click(object sender, RoutedEventArgs e)

{

DataSet ds = new DataSet();

string sql = "select * from tblOTRecord order by Project_Name";

ds = ClsDBAccess.mGetOrcDataset(sql, ClsDBAccess.eConn.INTRANET); // Custom method, it is ok, getting rows

if(ds.Tables[0].Rows.Count > 0)

{

Binding bind = new Binding();

listView1.DataContext = ds.Tables[0];

listView1.SetBinding(ListView.ItemsSourceProperty, bind);

}

}

Can you tell me ?

vickees vignesh replied to Abhi Rana on 12-Aug-09 03:29 AM
Hi Rana,

Can you tell the columns name correctly also try

Select * from...
instead of * write columns name

The same column name must be in the binding path you can have any header...

<GridViewColumn Header="Project_Name" Width="100" DisplayMemberBinding="{Binding Path=Project_Name}" />


Try this out  and revrt me

Vickee Vignesh

Re

Ravenet Rasaiyah replied to Abhi Rana on 12-Aug-09 04:51 AM
Hi

Just simple


Following Code is unable to bind data into Grid

<Button Height="23" Margin="0,12,35,0" Name="button1" VerticalAlignment="Top" HorizontalAlignment="Right" Width="46" Click="button1_Click">Go</Button>

<ListView Name="listView1" Margin="0,41,0,0">

<ListView.View>

<GridView>

<GridViewColumn Header="User_Name" Width="100" DisplayMemberBinding="{Binding Path=User_Name}"/>

<GridViewColumn Header="Project_Name" Width="100" DisplayMemberBinding="{Binding Path=Project_Name}" />

<GridViewColumn Header="CD_Name" Width="100" DisplayMemberBinding="{Binding Path=CD_Name}"/>

<GridViewColumn Header="IsOracle" Width="100" DisplayMemberBinding="{Binding Path=IsOracle}" />

</GridView>

</ListView.View>

</ListView>

</Grid>

</Window>



private void button1_Click(object sender, RoutedEventArgs e)

{

DataSet ds = new DataSet();

string sql = "select * from tblOTRecord order by Project_Name";

ds = ClsDBAccess.mGetOrcDataset(sql, ClsDBAccess.eConn.INTRANET); // Custom method, it is ok, getting rows

if(ds.Tables[0].Rows.Count > 0)

{

listView1.ItemSource= ds.Tables[0].DefaultView;


}

}

NOTE:Please add this property in your list view

<ListView Name="listView1" Margin="0,41,0,0" ItemSource="{Binding}">
////
</ListView >


Thank you
http://www.codegain.com

Columns are not visible....

Abhi Rana replied to vickees vignesh on 12-Aug-09 04:56 AM

After clicking the button, gridview is getting scrollbar but columns are not visible.

Please guide

ItemSource="{Binding}"> is used, but columns are not visible
Abhi Rana replied to Ravenet Rasaiyah on 12-Aug-09 04:58 AM
end of post
RE
Ravenet Rasaiyah replied to Abhi Rana on 12-Aug-09 05:32 AM
Hi

Are you  check your query column and DataBindinfMember Name are same( even case sensitive also)

Please make sure.and try if you have any question, please email my email(becuase of not working email in eggheadcafe)

vrrave@gmail.com


thank you
http://www.codegain.com

Datagrid is load, but enable to see records
Abhi Rana replied to Ravenet Rasaiyah on 12-Aug-09 05:40 AM

I have textbox that is showing no. of rows load via dataset.

GridView is also getting vertical scroll after filling, but not the data.

THANKS ALOT RAVEEN - For solving my query
Abhi Rana replied to Ravenet Rasaiyah on 12-Aug-09 06:14 AM
THANKS ALOT RAVEEN - For solving my query
welcome Buddy :)
Ravenet Rasaiyah replied to Abhi Rana on 12-Aug-09 06:19 AM
end of post