Scroll to Selected Row in XamDataGrid - wpf

I have an Infragistics 15.1 WPF XamDataGrid that refreshes when the user saves data elsewhere on the form. I have figured out how to programmatically select the row that was selected before saving. My problem is that if that row is not one of the top rows on the grid the user has to scroll back down to the highlighted row. Is there a way to have the grid scroll to the selected row?
XAML Code
<inf:XamDataGrid GroupByAreaLocation="None"
SelectedDataItem="{Binding SelectedPayItem, Mode=TwoWay}"
ActiveDataItem="{Binding SelectedPayItem, Mode=OneWay}"
DataSource="{Binding SelectedProject.ContractProjectPayItems}" ScrollViewer.VerticalScrollBarVisibility="Auto"
Grid.Row="2" Grid.Column="2" Grid.ColumnSpan="2" Margin="2.8,3.4,3,2.8">
View Model Code
private void SetSelectedPayItem()
{
if (SelectedProject != null)
{
if (SelectedProject.ContractProjectPayItems.Count() > 0)
{
if (SelectedProject.SelectedPayItemLineNbr == -1)
{
SelectedPayItem = SelectedProject.ContractProjectPayItems.First();
}
else
{
if (strLineItemNbr != null)
{
SelectedPayItem = SelectedProject.ContractProjectPayItems.FirstOrDefault(CPPI => CPPI.LineItemNbr == strLineItemNbr);
}
else
{ SelectedPayItem = SelectedProject.ContractProjectPayItems[SelectedProject.SelectedPayItemLineNbr]; }
}
}
else
{
SelectedPayItem = null;
}
}
}
string strLineItemNbr;
private ContractProjectPayItemModel _selectedPayItem;
public ContractProjectPayItemModel SelectedPayItem
{
get { return _selectedPayItem; }
set
{
_selectedPayItem = value;
if (_selectedPayItem != null)
{
SelectedProject.SelectedPayItemLineNbr = SelectedProject.ContractProjectPayItems.IndexOf(_selectedPayItem);
if (_selectedPayItem.ItemInstallations == null)
{
var oItemInstallation = new clsItemInstallation();
_selectedPayItem.ItemInstallations = oItemInstallation.GetItemInstallsByProjectPayItem(_selectedPayItem.ProjectGuid, _selectedPayItem.PayItemGuid);
foreach (var itemInstallation in _selectedPayItem.ItemInstallations)
{
itemInstallation.PropertyChanged += ItemInstallationsPropertyChanged;
itemInstallation.AcceptChanges();
}
_selectedPayItem.AcceptChanges();
foreach (var ii in SelectedProject.ContractProjectPayItems)
{
if (ii.ItemInstallations != null)
{
foreach (var i2 in ii.ItemInstallations)
{
i2.AcceptChanges();
}
}
}
RaisePropertyChanged("TotalInstallQty");
}
_itemInstallViewModel.SelectedProjectLineItem = SelectedPayItem;
strLineItemNbr = SelectedPayItem.LineItemNbr;
}
RaisePropertyChanged("SelectedPayItem");
RaisePropertyChanged("IsBitumen");
//----------------------------------
// Populate the User Control tabs.
//----------------------------------
PopulateUserControls();
SetSelectedItemInstallation();
RaisePropertyChanged("TotalInstallQty");
}
}

I was able to get this to behave the way I wanted by moving the SelectedDataItem inside of the DataSource property.
<inf:XamDataGrid GroupByAreaLocation="None"
DataSource="{Binding SelectedProject.ContractProjectPayItems}"
ScrollViewer.VerticalScrollBarVisibility="Auto"
SelectedDataItem="{Binding SelectedPayItem, Mode=TwoWay}"
ActiveDataItem="{Binding SelectedPayItem, Mode=TwoWay}"
Grid.Row="2" Grid.Column="2" Grid.ColumnSpan="2" Margin="2.8,3.4,3,2.8">
</inf:XamDataGrid>

Related

On source change TextBox value is not binding to property in MVVM

My ViewModel code to bind my Textbox is as followes
private float _maxKaxCalculate;
public float MaxKaxCalculate
{
get { return _maxKaxCalculate; }
set
{
if (value != _maxKaxCalculate)
{
_maxKaxCalculate = value;
OnPropertyChanged("MaxKaxCalculate");
}
}
}
public void CalculateMaxKaz()
{
if (CouponList.Count > 0)
{
_maxKaxCalculate = 1;
foreach (CouponDC cDC in CouponList)
{
_maxKaxCalculate *= cDC.Rate;
}
_maxKaxCalculate *= Convert.ToSingle(TutarValue);
}
else
_maxKaxCalculate = 0;
_maxKaxCalculate = Convert.ToSingle(Math.Round(_maxKaxCalculate, 2));
}
private float _tutarValue;
public float TutarValue
{
get { return _tutarValue; }
set
{
if (value != _tutarValue)
{
_tutarValue = value;
OnPropertyChanged("TutarValue");
}
}
}
My View section has the following code of the textbox
<TextBox Width="65" Text="{Binding Path=MaxKaxCalculate,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,StringFormat=N2}" Style="{StaticResource Input1}" Grid.Row="3" Grid.Column="3" HorizontalAlignment="Left" Margin="0,2,0,3" />
My _maxKaxCalculate variable is getting some correct value but Textbox is not getting that value in View.Is UI refresh required or BeginInvoke required?please suggest.
If you set
_maxKaxCalculate = 0;
there will be no notification about the change. Use
MaxKaxCalculate = 0;
to use the setter of the property with notification.

RIch Text box Requirement in WPF

I have a requirement in WPF in which...
I want Rich text box to be used as dateTemplate for a listview for one particular column(which has remarks)
I have set of key word (add, search, location etc..)
In that column I want all those keywords to be highlighted in yellow colour.
I have another TextBox .If I type any word for searching in that text box and it exists in listview then it should be highlighted with green.
If I search the keyword which are in yellow then they should not be highlighted with green they should be in yellow colour.
If I have “added” word in which add is highlighted in yellow then when I search for “added” “add” should be in yellow and “ed” should be in green.
Any help is appreciated. I have tried several ways but failed at the last point above.
//Code snippet
// Xaml File
<Window x:Class="RichtextBoxhighlight.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:src="clr-namespace:RichtextBoxhighlight"
Title="MainWindow" Height="406" Width="855"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Window.Resources>
<src:ContentPlainConverter x:Key="typeConverter" />
<src:TestConvertor x:Key="spaceRem"/>
<Style x:Key="RichTextBoxWithRoundedCorners" TargetType="{x:Type RichTextBox}">
<Style.Resources>
<Style x:Key="{x:Type FlowDocument}" TargetType="{x:Type FlowDocument}">
<Setter Property="OverridesDefaultStyle" Value="true"/>
</Style>
</Style.Resources>
</Style>
</Window.Resources>
<Grid>
<TextBox Margin="114,14,130,255" Name="txtText" />
<Grid>
<ListView Height="241" ItemsSource="{Binding CollRemarks}" HorizontalAlignment="Left" Margin="0,126,0,0" Name="listView1" VerticalAlignment="Top" Width="827" >
<ListView.View >
<GridView >
<GridViewColumn Header="Type" Width="80" DisplayMemberBinding="{Binding Path=type}"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Operatorid}" Width="70">
<GridViewColumnHeader Tag="CreatedEmployeeId" Content="Operator"/>
</GridViewColumn>
<GridViewColumn Width="710">
<GridViewColumn.CellTemplate>
<DataTemplate>
<src:BindableRichTextBox Document ="{Binding Path=remarks, Converter= {StaticResource typeConverter}}" HighlightPhrase="{Binding ElementName=txtText, Path=Text,Converter={StaticResource spaceRem}}" IsReadOnly="True" Background="Transparent" BorderBrush="Transparent" BorderThickness="0"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
<GridViewColumnHeader Tag="CommentText" Content="Remark" />
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
</Grid>
</Window>
//BindableRichTextBox class :
namespace RichtextBoxhighlight
{
public class BindableRichTextBox : RichTextBox
{
public static string oldstring;
public static readonly DependencyProperty DocumentProperty =
DependencyProperty.Register("Document", typeof(FlowDocument),
typeof(BindableRichTextBox), new FrameworkPropertyMetadata
(null, new PropertyChangedCallback(OnDocumentChanged)));
public static readonly DependencyProperty HighlightPhraseProperty =
DependencyProperty.Register("HighlightPhrase", typeof(string),
typeof(BindableRichTextBox), new FrameworkPropertyMetadata(String.Empty, FrameworkPropertyMetadataOptions.AffectsRender,
new PropertyChangedCallback(UpdateHighlighting)));
public string HighlightPhrase
{
get { return (string)GetValue(HighlightPhraseProperty); }
set { SetValue(HighlightPhraseProperty, value); }
}
private static void UpdateHighlighting(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
//invoked on text box search
ApplyHighlight(d as BindableRichTextBox);
ApplyAllHighlight(d as BindableRichTextBox);
}
// Gets or sets the Document of RichtextBox
public new FlowDocument Document
{
get
{
return (FlowDocument)this.GetValue(DocumentProperty);
}
set
{
this.SetValue(DocumentProperty, value);
}
}
// Method invoked on documnet formation.
public static void OnDocumentChanged(DependencyObject obj,
DependencyPropertyChangedEventArgs args)
{
try
{
RichTextBox rtb = (RichTextBox)obj;
// ApplyHighlight(rtb as BindableRichTextBox);
rtb.Document = (FlowDocument)args.NewValue;
ApplyAllHighlight(rtb as BindableRichTextBox);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
/// <summary>
/// Implementation logic for Text Changed search highlight
/// </summary>
private static void ApplyHighlight(BindableRichTextBox tb)
{
try
{
if (tb != null && tb.Document != null)
{
string highlightPhrase = tb.HighlightPhrase;
// Frame the highlight word to skip them from getting highlighted by searchtext
string highlightWords = "(";
for (int i = 0; i < MainWindow.Highlightwords.Count; i++)
{
highlightWords += MainWindow.Highlightwords[i];
if (i != MainWindow.Highlightwords.Count - 1)
highlightWords += "|";
}
highlightWords += ")";
var start = tb.Document.ContentStart;
TextRange range = new TextRange(start, tb.Document.ContentEnd);
range.ClearAllProperties();
Regex ignore = new Regex(highlightWords, RegexOptions.Compiled | RegexOptions.IgnoreCase);
string Text = range.Text;
int index_match = 0;
if (highlightPhrase != string.Empty && highlightPhrase != null)
{
while (start != null && start.CompareTo(tb.Document.ContentEnd) < 0)
{
// Comparison to skip the key words in the column to be highlighted
if (start.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text)
{
index_match = Text.IndexOf(highlightPhrase, StringComparison.OrdinalIgnoreCase);
if (index_match >= 0)
{
//Ignore all Keyword highlight by incrementing start and moving to next match
MatchCollection matches = ignore.Matches(start.GetTextInRun(LogicalDirection.Forward));
if (matches != null)
{
for (int i = 0; i < matches.Count; i++)
{
if ((index_match >= matches[i].Index && index_match <= matches[i].Index + matches[i].Length))
{
start = start.GetPositionAtOffset(matches[i].Index + matches[i].Length, LogicalDirection.Forward);
Text = new TextRange(start.GetInsertionPosition(LogicalDirection.Forward), start.DocumentEnd).Text;
//Highlight the search text if part before keyword
if (highlightPhrase.Length > matches[i].Length)
{
var textrange = new TextRange(start.GetPositionAtOffset(0, LogicalDirection.Forward), start.GetPositionAtOffset(highlightPhrase.Length - matches[i].Length, LogicalDirection.Backward));
textrange.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(Colors.Green));
}
if (start != null && start.CompareTo(tb.Document.ContentEnd) < 0)
{
index_match = Text.IndexOf(highlightPhrase, StringComparison.OrdinalIgnoreCase);
if (index_match >= 0)
{
matches = ignore.Matches(start.GetTextInRun(LogicalDirection.Forward));
if (matches != null && matches.Count > 0)
i--;
}
else
break;
}
}
else if ((highlightPhrase.Length - 1 >= matches[i].Index && highlightPhrase.Length + index_match <= matches[i].Index + matches[i].Length))
{
//Highlight the search text if part after keyword
var textrange = new TextRange(start.GetPositionAtOffset(index_match, LogicalDirection.Forward), start.GetPositionAtOffset(matches[i].Index, LogicalDirection.Backward));
textrange.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(Colors.Green));
start = start.GetPositionAtOffset(matches[i].Index + matches[i].Length, LogicalDirection.Forward);
Text = new TextRange(start.GetInsertionPosition(LogicalDirection.Forward), start.DocumentEnd).Text;
if (start != null && start.CompareTo(tb.Document.ContentEnd) < 0)
{
index_match = Text.IndexOf(highlightPhrase, StringComparison.OrdinalIgnoreCase);
if (index_match >= 0)
{
matches = ignore.Matches(start.GetTextInRun(LogicalDirection.Forward));
if (matches != null && matches.Count > 0)
i--;
}
else
break;
}
}
}
}
if (index_match >= 0 && start != null && (start.CompareTo(tb.Document.ContentEnd) < 0))
{
//Highlight the search text typed if not part of Keywords
var textrange = new TextRange(start.GetPositionAtOffset(index_match, LogicalDirection.Forward), start.GetPositionAtOffset(index_match + highlightPhrase.Length, LogicalDirection.Backward));
textrange.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(Colors.Green));
start = textrange.End;
Text = new TextRange(textrange.End, start.DocumentEnd).Text;
}
}
else
break;
}
if (start != null && start.CompareTo(tb.Document.ContentEnd) < 0)
start = start.GetNextContextPosition(LogicalDirection.Forward);
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
/// <summary>
/// Implementation logic for key words highlight
/// </summary>
private static void ApplyAllHighlight(BindableRichTextBox rtb)
{
try
{
if (rtb != null)
{
string highlightWords = "(";
for (int i = 0; i < MainWindow.Highlightwords.Count; i++)
{
highlightWords += MainWindow.Highlightwords[i];
if (i != MainWindow.Highlightwords.Count - 1)
highlightWords += "|";
}
highlightWords += ")";
Regex reg = new Regex(highlightWords, RegexOptions.Compiled | RegexOptions.IgnoreCase);
var start = rtb.Document.ContentStart;
while (start != null && start.CompareTo(rtb.Document.ContentEnd) < 0)
{
if (start.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text)
{
var match = reg.Match(start.GetTextInRun(LogicalDirection.Forward));
var textrange = new TextRange(start.GetPositionAtOffset(match.Index, LogicalDirection.Forward), start.GetPositionAtOffset(match.Index + match.Length, LogicalDirection.Backward));
textrange.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(Colors.Yellow));
start = textrange.End;
}
start = start.GetNextContextPosition(LogicalDirection.Forward);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
//Content of list view remarks column and keywords to be highlighted
//Key word to be highlighted
Highlightwords = new List<string>();
Highlightwords.Add("mment");
Highlightwords.Add("ADD");
Highlightwords.Add("LOCATION");
Highlightwords.Add("arch");
// Remarks in list view
CollRemarks = new ObservableCollection<evcom>();
string remar = "search for added comments in location added";
CollRemarks.Add(new evcom { type = "Info", Operatorid = "1728", remarks = remar });
remar = "searched for added add comments in location added LOCATIONS";
CollRemarks.Add(new evcom { type = "Info", Operatorid = "1783", remarks = remar });

Popup and ComboBox binding with Silverlight

I have a problem regarding the comportment my ComboBox.
First I use a combobox to display all elements in a IEnumarale.
Then, with a button wich open a popup, the user can add an alement to that list.
The problem is that when the user validate his choice and close the popup, the element is not automatly added to the ComboBox without doing a refresh of the page.
The combobox is coded as follows :
<telerik:RadComboBox x:Name="MyElements"
SelectionChanged="MyElements_OnSelectionChanged"
ItemTemplate="{StaticResource ComboBoxElementsTemplate}"
ItemsSource="{Binding ListElements}"/>
The constructor of the list is :
public IEnumerable<Element> ListElements
{
get { return _listElements; }
set
{
_listElements= value;
RaisePropertyChange("ListElements");
}
}
And the code behind of the button to validate the user choice in the popup :
private ObservableCollection<HistoriqueElement> elementList = null;
private void SelectClick(object sender, RoutedEventArgs e)
{
var element= _GridList.SelectedItem as HistoriquePasserelle;
if (_GridList.SelectedItem != null)
{
var installation = this.DataContext as Installation;
if (installation != null && element!= null)
{
element.DateFin = DateTime.Now;
HistoriqueElement newElement= new HistoriqueElement()
{
Installation = installation,
ContactAction = GlobalActeurs.Current.CurrentContact,
Date = DateTime.Now,
Element = element.Element,
StatutElement = element.StatutElement ,
Owner= element.Owner,
};
elementList.Remove(element);
}
MainPage.ClosePopup();
}
}
When the user choose a new element in the list display in the popup and validate his choice, he returns to the main page, but his choice is not automatically added to the combobox.
I can post you any parts of the code.
Thank you in advance.
The method OnDataContextChanged :
public override void OnDataContextChanged(DependencyPropertyChangedEventArgs e)
{
if (e.NewValue is Installation)
{
if (MainPage.CurrentInstallation.LastElements != null)
{
ListElements = MainPage.CurrentInstallation.LastElements;
MyElements.SelectedIndex = 0;
}
else
{
LoadOperation<Element> operation =
_context.Load(_context.GetCurrentElementsByInstallationId(MainPage.CurrentInstallation.Id));
this._busy.IsBusy = true;
operation.Completed += delegate
{
this._busy.IsBusy = false;
if (operation.ManageError())
{
ListElements = operation.Entities;
}
};
}
this.DataContext = this;
}
else
{
RaisePageTitleChanged();
if (MainPage.CurrentInstallation == null)
return;
}
if (MyElements.SelectedItem == null && MyElements.Items.Any())
{
MyElements.SelectedIndex = 0;
}
}
If the collection the ItemsSource is bound to implement INotifyCollection changed, that is, it's an ObservableCollection<>, then the combobox will be notified of any changes to the collection and you will not need to rebind or refresh, it will all be automatic.
Once you add the item to the list, bind the itemsource to the combobox, then you dont have to refersh.
MyElements.ItemsSource = ListElements

Finding control within WPF itemscontrol

Hi i have few a single textbox within the the datatemplate for itemscontrol. When i bind the itemcontrols to a observable collection i get two text boxes. But i need to do some manipulations based on each of the text boxes for which i want to find each textbox seperatly using some id.
Can anybody help on how to find a control witin the itemscontrol in WPF.
Using the ItemContainerGenerator you can obtain the generated container for an item and traverse the visual tree downwards to find your TextBox. In the case of an ItemsControl it will be a ContentPresenter, but a ListBox will return a ListBoxItem, ListView a ListViewItem, etc.
ContentPresenter cp = itemsControl.ItemContainerGenerator.ContainerFromItem(item) as ContentPresenter;
TextBox tb = FindVisualChild<TextBox>(cp);
if (tb != null)
{
// do something with tb
}
public static T FindVisualChild<T>(DependencyObject depObj) where T : DependencyObject
{
if (depObj != null)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
if (child != null && child is T)
{
return (T)child;
}
T childItem = FindVisualChild<T>(child);
if (childItem != null) return childItem;
}
}
return null;
}
You can also obtain the container by index if you want by using
itemsControl.ItemContainerGenerator.ContainerFromIndex(0);
Thanks Bryce, I tried to tick the up arrow but it says my rating is too low! Sorry!
I amended the code to return all a list of all the children of the given type as it was what I needed and thought someone else might find it useful.
Thanks again Bryce, really helpful - sorry about the rating thing!
public static List<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
{
List<T> list = new List<T>();
if (depObj != null)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
if (child != null && child is T)
{
list.Add((T)child);
}
List<T> childItems = FindVisualChildren<T>(child);
if (childItems != null && childItems.Count() > 0)
{
foreach (var item in childItems)
{
list.Add(item);
}
}
}
}
return list;
}
You may want to try using VisualTreeHelper. The properties on ItemsControl itself will only allow you to get the data its bound to, not the template instances used to visualize the data, while VisualTreeHelper allows you to browse around the visual tree as WPF has rendered it.
If you iterate through the parent ItemControl's visual children (recursively), you shouldn't have any difficulty locating the text boxes you are seeing on screen.
Another example:
private void DataGridBank_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
try
{
switch (e.Key)
{
case Key.Down:
if ((DataGridBank.SelectedIndex + 1) <= DataGridBank.Items.Count)
{
DataGridBank.SelectedIndex = DataGridBank.SelectedIndex + 1;
FocusCell();
}
break;
case Key.Up:
if ((DataGridBank.SelectedIndex - 1) >= 0)
{
DataGridBank.SelectedIndex = DataGridBank.SelectedIndex - 1;
FocusCell();
}
break;
case Key.Enter:
case Key.Tab:
FocusCell();
break;
}
}
catch (Exception ex)
{
}
}
private void DataGridBank_Loaded(object sender, RoutedEventArgs e)
{
try
{
if (DataGridBank.Items.Count > 0)
{
DataGridBank.SelectedIndex = 0;
FocusCell();
}
}catch(Exception ex)
{
}
}
private void FocusCell()
{
var selectedRow = (DataGridRow)DataGridBank.ItemContainerGenerator.ContainerFromItem(DataGridBank.SelectedItem);
var textImport = FindVisualChild<TextBox>(selectedRow);
textImport.Focus();
textImport.SelectAll();
}
public static T FindVisualChild<T>(DependencyObject depObj) where T : DependencyObject
{
if (depObj != null)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
if (child != null && child is T)
{
return (T)child;
}
T childItem = FindVisualChild<T>(child);
if (childItem != null) return childItem;
}
}
return null;
}
If you have data grid and template column, which contains data template,
you can use the following code sample
<DataGridTemplateColumn x:Name="photoPathColumn" Header="{x:Static resx:FrmResource.Photo}">
<DataGridTemplateColumn.CellEditingTemplate x:Uid="keyelm">
<DataTemplate x:Name="dodo">
<StackPanel Orientation="Horizontal" Height="Auto">
<TextBlock x:Name="photo" x:Uid="imageFile" Text="{Binding Path=PhotoPath}" />
<Button x:Name="Browse" Content="..." Click="Browse_Click" />
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
photoPathColumn.CellEditingTemplate.FindName("photo",photoPathColumn.GetCellContent(CustomersDataGrid.CurrentItem))

How to display an initial value in a WPF ComboBox

XAML Code
<ComboBox Height="23" Margin="69,105,111,0" Name="comboBox1" VerticalAlignment="Top" ItemsSource="{Binding StoreTypeTable}" DisplayMemberPath="StoreTypeName" SelectedValuePath="StoreTypeName" IsSynchronizedWithCurrentItem="True" SelectedIndex="0"/>
C# Code:
My Class:
class StoreTypes:nuClass
{
private WSOntsu.ServiceSoapClient _WS;
private WSOntsu.OSM007StoreType _DS;
public StoreTypes()
{
try
{
_WS = new WpfOntsu.WSOntsu.ServiceSoapClient();
_DS = _WS.lstStoreType();
}
catch (Exception e)
{
bResult = false;
sResult = e.Message;
}
bResult = _DS.Osm007getStoreType.Rows.Count > 0;
}
public DataTable StoreTypeTable
{
get { return _DS.Osm007getStoreType; }
}
}
My Page load:
StoreTypes _ST = new StoreTypes();
comboBox1.ItemsSource = _ST.StoreTypeTable.Rows;
How to display combo initial value when page is loading?
plz help me.
Your request is very unclear. If you want to select the first value in the ComboBox, you can do something like:
StoreTypes _ST = new StoreTypes();
comboBox1.ItemsSource = _ST.StoreTypeTable.Rows;
if (comboBox1.Items.Count > 0)
{
comboBox1.SelectedIndex = 0;
}
If that's not what you want, please edit your question.

Resources